我正在完成我的论文,他们要求目录中的“目录 - 续”标题(显示它是否流入第二页)居中。
我以为我可以找到生成 ToC 的代码并对其进行一些自定义,但我甚至找不到生成它的内容......
有人知道我该如何解决这个问题,或者代码在哪里吗?
答案1
如果您希望在正文中将此“继续”标题作为继续目录上方的标题,则可以使用afterpage
包。下面是一个例子:
\documentclass{report}
\usepackage{afterpage}
\DeclareRobustCommand*{\contheading}{%
\afterpage{{\normalfont\large\bfseries\centering
Table of Contents - Continued\par\bigskip}}}
\begin{document}
\addtocontents{toc}{\contheading}
\tableofcontents
\chapter{One}
...
\chapter{Twenty}
\section{One}
\chapter{Twenty one}
\section{One}
...
\end{document}
这里我定义了一个宏\contheading
,它将我们的文本打印到下一页。该命令将被写入文件.toc
,在那里\tableofcontents
可以读取它。为了保护此命令,以便它写入.toc
文件而不被展开,我使用了\DeclareRobustCommand
。
如果目录有更多页面,您可以\contheading
在适当的位置重复添加。这可能容易出错,因为如果有很多页面,您可能会忘记其中的一页,而使用标题条目的方法可能更合适。
如果您不想在正文中使用标题,而是在页面标题中使用,请使用类或标题包的功能,例如fancyhdr
或scrlayer-scrpage
。然后,例如,\markboth
可用于覆盖现有的标题条目:
\newcommand*{\contheading}{Table of Contents - Continued}% in the preamble
...
% later at the beginning of the text:
\addtocontents{toc}{\protect\markboth{\contheading}{\contheading}}
这里我用来防止在写入文件时\protect
发生扩展。\markboth
.toc
这是一个完整的例子:
\documentclass{report}
% Some general header style settings:
\usepackage{fancyhdr}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[C]{\leftmark}
\pagestyle{fancy}
% The text of our heading:
\newcommand*{\contheading}{Table of Contents - Continued}
\begin{document}
% Now we write the command to the TOC:
\addtocontents{toc}{\protect\markboth{\contheading}{\contheading}}
\tableofcontents
\chapter{One}
...
\chapter{Twenty}
\section{One}
\chapter{Twenty one}
\section{One}
...
\end{document}
答案2
抱歉这么晚才回答;你完成论文了吗?
\documentclass[twoside]{report}
\usepackage{etoc}
% to activate some page headers:
\pagestyle{headings}
% but we need to customize the appearance of the page headers
\makeatletter
% Make them centered.
\def\@oddhead {\hfil {\bfseries \rightmark }\hfil }
\def\@evenhead {\hfil {\bfseries \leftmark }\hfil }
\makeatother
\renewcommand{\etocaftertitlehook}%
% the default \tableofcontents of class report
% does a \chapter* which puts \contentsname
% in the left and right marks. We must counteract that,
% hence we use this hook which is executed after this \chapter*
{\markboth{Table of Contents - Continued}{Table of Contents - Continued}}
\renewcommand{\etocaftertochook}
% we need to reset the header style to erase our customization
% of \@oddhead and \@evenhead, but this must be done *after*
% the last page of the TOC. Thus either add to the source
% \pagestyle{headings} (or plain, or whatever) *after* the first
% \chapter or provoke a \clearpage (which will happen anyhow)
% explictely via this hook and take this opportunity to reset
% the \@oddhead and \@evenhead things.
% Doing this in an \afterpage was tried, but failed.
{\clearpage\pagestyle{headings}% or plain or whatever
}
\title{Test document}
\author{Anonymous}
\begin{document}
\maketitle
\tableofcontents
\newcount\loopcount
\loopcount 50
\loop
\chapter{This is a chapter}
\section {first section here}
hello
\clearpage
\section {second section here}
world
\clearpage
\section {third section here}
!
\advance\loopcount-1
\ifnum\loopcount>0
\repeat
\end{document}
目录的第二页
和第三页
等等,直到最后一页。