删除多页目录页脚中的页码

删除多页目录页脚中的页码

我正在尝试删除目录页脚中默认显示的页码。我能够对一页长的目录执行此操作,如下所示:

\documentclass[final]{book}
\pagestyle{plain}

\begin{document}

\tableofcontents
\thispagestyle{empty}

\chapter{Chapter 1}
\chapter{Chapter 2}
\chapter{Chapter 3}
\chapter{Chapter 4}

\end{document}

但是,对于占用 2 页或更多页的长目录,\thispagestyle{empty}仅从目录最后一页的页脚中删除页码,但所有其他页面都有此编号:

\documentclass[final]{book}
\pagestyle{plain}

\begin{document}

\tableofcontents
\thispagestyle{empty}

\chapter{Chapter 1}
\chapter{Chapter 2}
\chapter{Chapter 3}
\chapter{Chapter 4}
\chapter{Chapter 5}
\chapter{Chapter 6}
\chapter{Chapter 7}
\chapter{Chapter 8}
\chapter{Chapter 9}
\chapter{Chapter 10}
\chapter{Chapter 11}
\chapter{Chapter 12}
\chapter{Chapter 13}
\chapter{Chapter 14}
\chapter{Chapter 15}
\chapter{Chapter 16}
\chapter{Chapter 17}
\chapter{Chapter 18}
\chapter{Chapter 19}
\chapter{Chapter 20}
\chapter{Chapter 21}
\chapter{Chapter 22}
\chapter{Chapter 23}
\chapter{Chapter 24}
\chapter{Chapter 25}
\chapter{Chapter 26}
\chapter{Chapter 27}
\chapter{Chapter 28}
\chapter{Chapter 29}
\chapter{Chapter 30}
\chapter{Chapter 31}
\chapter{Chapter 32}
\chapter{Chapter 33}
\chapter{Chapter 34}
\chapter{Chapter 35}
\chapter{Chapter 36}
\chapter{Chapter 37}
\chapter{Chapter 38}
\chapter{Chapter 39}
\chapter{Chapter 40}
\chapter{Chapter 41}
\chapter{Chapter 42}
\chapter{Chapter 43}
\chapter{Chapter 44}
\chapter{Chapter 45}
\chapter{Chapter 46}
\chapter{Chapter 47}
\chapter{Chapter 48}
\chapter{Chapter 49}
\chapter{Chapter 50}
\chapter{Chapter 51}
\chapter{Chapter 52}
\chapter{Chapter 53}
\chapter{Chapter 54}
\chapter{Chapter 55}
\chapter{Chapter 56}
\chapter{Chapter 57}
\chapter{Chapter 58}
\chapter{Chapter 59}
\chapter{Chapter 60}
\chapter{Chapter 61}
\chapter{Chapter 62}

\end{document}

我发现我可以使用\addtocontents{toc}{\protect\thispagestyle{empty}}before \chapterentry 来从目录中将出现给定章节的页面中删除页脚。但是,这要求我\addtocontents{toc}{\protect\thispagestyle{empty}}在每个\chapter命令之前添加,或者至少在目录的每个页面上手动为一个章节执行此操作。

是否有更直接的方法可以从目录中删除页脚,无论目录有多长?

答案1

正如您所说,该\thispagestyle{...}命令仅影响当前页面,因此它对多页目录没有帮助,除非像您在解决方案中所做的那样,确保它在每个页面上至少被调用一次。

要在多个页面上临时更改页脚,可以使用\pagestyle{...}。因此,第一个要尝试的简单方法是:

\pagestyle{empty}
\tableofcontents
\clearpage
\pagestyle{plain}

注意该\clearpage命令,以便以下\pagestyle命令仅对下一页生效,而不会对目录的最后一页生效。

但是,有一个问题:\tableofcontents内部调用\chapter*{...},它本身又调用\thispagestyle{plain}(见book.cls源代码)。因此,第一页仍将具有“普通”页脚样式。为了解决这个问题,我没有比暂时禁用命令\thispagestyle本身更优雅的解决方案;总代码块如下:

\pagestyle{empty}
{
  \renewcommand{\thispagestyle}[1]{}
  \tableofcontents
}
\clearpage
\pagestyle{plain}

注意这对括号,其目的是\thispagestyle在块之后将宏恢复到其原来的含义。

答案2

为了避免不必要的输入,您可以定义自定义宏以添加\addtocontents{toc}{\protect\thispagestyle{empty}}到每个目录条目。它不会影响文档编译时间,但您需要为您使用的每个部分命令定义类似的宏,如\section\subsection

\documentclass[final]{book}
\pagestyle{plain}

\def \mychapter#1{
\chapter{#1}
\addtocontents{toc}{\protect\thispagestyle{empty}}
}


\begin{document}

\tableofcontents
\thispagestyle{empty}

\mychapter{Chapter 1}
\mychapter{Chapter 2}
\mychapter{Chapter 3}
\mychapter{Chapter 4}
\mychapter{Chapter 5}
\mychapter{Chapter 6}
\mychapter{Chapter 7}
\mychapter{Chapter 8}
\mychapter{Chapter 9}
\mychapter{Chapter 10}
\mychapter{Chapter 11}
\mychapter{Chapter 12}
\mychapter{Chapter 13}
\mychapter{Chapter 14}
\mychapter{Chapter 15}
\mychapter{Chapter 16}
\mychapter{Chapter 17}
\mychapter{Chapter 18}
\mychapter{Chapter 19}
\mychapter{Chapter 20}
\mychapter{Chapter 21}
\mychapter{Chapter 22}
\mychapter{Chapter 23}
\mychapter{Chapter 24}
\mychapter{Chapter 25}
\mychapter{Chapter 26}
\mychapter{Chapter 27}
\mychapter{Chapter 28}
\mychapter{Chapter 29}
\mychapter{Chapter 30}
\mychapter{Chapter 31}
\mychapter{Chapter 32}
\mychapter{Chapter 33}
\mychapter{Chapter 34}
\mychapter{Chapter 35}
\mychapter{Chapter 36}
\mychapter{Chapter 37}
\mychapter{Chapter 38}
\mychapter{Chapter 39}
\mychapter{Chapter 40}
\mychapter{Chapter 41}
\mychapter{Chapter 42}
\mychapter{Chapter 43}
\mychapter{Chapter 44}
\mychapter{Chapter 45}
\mychapter{Chapter 46}
\mychapter{Chapter 47}
\mychapter{Chapter 48}
\mychapter{Chapter 49}
\mychapter{Chapter 50}
\mychapter{Chapter 51}
\mychapter{Chapter 52}
\mychapter{Chapter 53}
\mychapter{Chapter 54}
\mychapter{Chapter 55}
\mychapter{Chapter 56}
\mychapter{Chapter 57}
\mychapter{Chapter 58}
\mychapter{Chapter 59}
\mychapter{Chapter 60}
\mychapter{Chapter 61}
\mychapter{Chapter 62}

\end{document}

相关内容