如何设置book类part页页面风格为empty?

发布于 2024-10-19 15:17:49

想这样设置页眉页脚:\part所在页为empty,而\chapter所在页为plain
但是book文档类默认二者都采用plain风格,所以我以book.cls里关于\part的定义为基础,把它的页面风格重定义为emptypdflatex编译后报“你不能在垂直模式中使用\spacefactor”的错误。

\documentclass[openany]{book}
\usepackage{geometry}
    \geometry{papersize={10.5cm,14.85cm},showframe,margin=1cm}
\renewcommand{\part}{%
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi
  \thispagestyle{empty}%
  \if@twocolumn
    \onecolumn
    \@tempswatrue
  \else
    \@tempswafalse
  \fi
  \null\vfil
  \secdef\@part\@spart}
\begin{document}
\setlength{\parindent}{2em}
\title{title}
\author{author}
\date{date}
\maketitle
\tableofcontents
\part{}
\chapter{}
Hello\TeX{}!
\part{}
\chapter{}
Hello\TeX{}!
\end{document}

查看更多

关注者
0
被浏览
242
1 个回答
Sagittarius Rover
不喜欢LaTeX!!!

在你的代码中涉及@的内容前后加上\makeatletter\makeatother,以处理@的catcode的问题

\documentclass[openany]{book}
\usepackage{geometry}
\geometry{
    papersize={10.5cm,14.85cm},
    %showframe,
    margin=1cm,
    }
\makeatletter
\renewcommand{\part}{%
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi
  \thispagestyle{empty}%
  \if@twocolumn
    \onecolumn
    \@tempswatrue
  \else
    \@tempswafalse
  \fi
  \null\vfil
  \secdef\@part\@spart}
\makeatother
\begin{document}
    \setlength{\parindent}{2em}
    \title{title}
    \author{author}
    \date{date}
    \maketitle
    \tableofcontents
    \part{}
    \chapter{}
    Hello\TeX{}!
    \part{}
    \chapter{}
    Hello\TeX{}!
\end{document}

image.png

另一种等价的更优雅的是使用\patchcmd:

\usepackage{etoolbox}%
\patchcmd{\part}{\thispagestyle{plain}}{\thispagestyle{empty}}{}{}

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览