我怎样才能像图片所示那样将“章节”和“页面”放在目录标题下方?如果目录超过一页,我还必须将它们放在论文的下一页中。谢谢,
如果他们没有超链接就好了
答案1
我最初的答案是使用埃托克。
但主要思想却被卡尔科勒 回答:使用afterpage
。不同之处在于该方法现在与许多页面上的目录兼容。
接下来我想到可以用更简单的方式来完成。因此,我在这里提供了两个代码:一个etoc
根本不使用。但目录的格式化必须由某个包来完成,比如tocloft
。第二个使用etoc
来促进 OP 对章节标题的限制和一些格式定制。第二个代码示例的文档主体稍微复杂一些。在这种情况下,我们可以看到最后一个(第四个)目录页有些不完美。我还没有调查哪个方面afterpage
导致了这种情况。
% without etoc
\documentclass{book}
\usepackage[textheight=10cm]{geometry}% small page height for testing!
\usepackage{hyperref}
\usepackage{afterpage}
\newif\ifintoc
\newcommand*{\PrintChapterTocHeadline}
{\hbox to \linewidth{\textbf{Chapter}\hfill\textbf{Page}}\bigskip
\SetupNextPage}
\newcommand*{\SetupNextPage}
{\afterpage {\ifintoc\PrintChapterTocHeadline\fi}}
\addtocontents{toc}{\protect\PrintChapterTocHeadline}
\begin{document}
\begingroup\intoctrue
\tableofcontents
\endgroup
\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\end{document}
由于使用罗马数字来表示章节,因此左侧使用了相当大的空格。
% solution using etoc
\documentclass{book}
\usepackage[textheight=10cm]{geometry}
\usepackage{hyperref}
\usepackage{etoc}
\usepackage{afterpage}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% doing the thing for the chapter headline one each page.
%%%% here, using etoc.
\newif\ifintoc
\newcommand*{\PrintChapterTocHeadline}
{\hbox to \linewidth{\textbf{Chapter}\hfill\textbf{Page}}\bigskip
\afterpage {\ifintoc\PrintChapterTocHeadline\fi}}
% after title hook will take care of the first chapter headline
% nothing is written to the .toc file, hence other TOCs in the
% document can be done, not using that extra thing. Naturally
% the hook will have to be redefined
\renewcommand{\etocaftertitlehook}
{\parindent 0pt
\leftskip 0cm
\rightskip \tocright
\parfillskip -\rightskip
\PrintChapterTocHeadline
\intoctrue }
% etoc always typesets TOCs in a group. Thus the \ifintoc boolean
% will be false after the TOC completes.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Now using etoc also to customize the formatting itself.
%%%% I take this opportunity to write down some rather general
%%%% etoc line style definitions, for a look somewhat like the
%%%% standard looks, but customisable.
%%%% some dimensions are hard-coded, but for some I already define
%%%% associated lengths
\newlength{\tocright}
\setlength{\tocright}{0.75cm}
\newlength{\toclefti}
\setlength{\toclefti}{1.25cm}
\newlength{\tocleftii}
\setlength{\tocleftii}{2.75cm}
\newlength{\tocleftiii}
\setlength{\tocleftiii}{4.25cm}
% Code for page numbers on the right side.
\renewcommand*\etoctoclineleaders
{\hbox{\normalfont\normalsize\hbox to .6ex {\hss.\hss}}}
\newcommand*{\EndParWithPagenoInMarginAndLeaders}
{\nobreak\leaders\etoctoclineleaders\hfill
\nobreak\makebox[\tocright][r]{\mdseries\normalsize\etocpage}%
\par }
% version with no dot leaders:
\newcommand*{\EndParWithPagenoInMargin}
{\nobreak\hfill
\nobreak\makebox[\tocright][r]{\mdseries\normalsize\etocpage}%
\par}
\etocsetstyle{chapter}
{}
{\leavevmode\leftskip \toclefti }
{\llap{\makebox[\toclefti][l]{\bfseries\etocnumber.}}%
\etoclink{\bfseries\MakeUppercase{\etocthename}}% roman uppercase
\EndParWithPagenoInMargin}
{}
\etocsetstyle {section}
{}
{\leavevmode\leftskip \tocleftii }
{\llap{\makebox[\dimexpr\tocleftii-\toclefti\relax][l]{\etocnumber.}}%
\textsc{\etocname}% small caps
\EndParWithPagenoInMarginAndLeaders}
{\medskip}
\etocsetstyle {subsection}
{}
{\leavevmode\leftskip \tocleftiii }
{\llap{\makebox[\dimexpr\tocleftiii-\tocleftii\relax][l]{\etocnumber.}}%
\etocname
\EndParWithPagenoInMarginAndLeaders}
{\smallskip}
%\renewcommand*{\etoctoprule}{\hrule height 0pt\relax}
%\etocruledstyle [1]{\MakeUppercase{\contentsname}}
\etocsettocstyle
{\hbox to \linewidth{\hss \MakeUppercase{\contentsname}\hss}\bigskip}
{}
\renewcommand{\thechapter}{\Roman{chapter}}
\begin{document}
\tableofcontents
\chapter{Test}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\chapter{Test}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\section{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\chapter{Test}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\section{Test}
\subsection{subsection}
\subsection{subsection}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\end{document}
答案2
希望你的目录不会超过两页,这样就可以了。
在第一章之前添加以下几行
\addtocontents{toc}{\protect\contentsline{chapter}{Chapter}{Page}{}}
\addtocontents{toc}{\protect\vspace*{15pt}}
\addtocontents{toc}{\protect\afterpage{\hspace*{-1.3em}\bfseries Chapter\hfill Page}}
\addtocontents{toc}{\protect\afterpage{\vspace*{25pt}}}
前两行将所需的内容添加到目录的第一页,而后两行(借助\afterpage
同一个包中的命令)将其添加到目录的第二页。
梅威瑟:
\documentclass{book}
\usepackage{hyperref}
\usepackage{afterpage}
\begin{document}
\tableofcontents
\addtocontents{toc}{\protect\contentsline{chapter}{Chapter}{Page}{}}
\addtocontents{toc}{\protect\vspace*{15pt}}
\addtocontents{toc}{\protect\afterpage{\hspace*{-1.3em}\bfseries Chapter\hfill Page}}
\addtocontents{toc}{\protect\afterpage{\vspace*{25pt}}}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\chapter{Test}
\section{Test}
\end{document}
输出: