我正在使用此代码在每章之前获取目录中的单词 Chapter。
\documentclass[a4paper]{book}
\usepackage{tocloft,calc}
\renewcommand{\cftchappresnum}{Chapter }
\AtBeginDocument{\addtolength\cftchapnumwidth{\widthof{\bfseries Chapter }}}
\begin{document}
\tableofcontents
\include{Intro}
\cleardoublepage
\begin{appendices}
\renewcommand{\thesection}{\arabic{section}}
\include{Appendix}
\end{appendices}
\end{document}
此代码还在附录前添加了 Chapter 字。我想知道如何在目录中的附录前添加单词 Supplementary。
答案1
您必须在读取文件时进行更改.toc
:这是如何执行此操作的示例。之所以要进行双重更改,\unexpanded
是因为toc
条目首先写入.aux
文件中,然后写入.toc
,因此我们必须对其进行两次保护。可以添加多个\protect
,但这肯定更容易编写。
\documentclass[a4paper]{book}
\usepackage{tocloft,calc}
\newcommand{\setupname}[1]{%
\addtocontents{toc}{%
\unexpanded{\unexpanded{%
\renewcommand{\cftchappresnum}{#1 }%
\setlength\cftchapnumwidth{\widthof{\bfseries #1 }}%
\addtolength\cftchapnumwidth{\fixedchapnumwidth}%
}}%
}%
}
\AtBeginDocument{\edef\fixedchapnumwidth{\the\cftchapnumwidth}}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\setupname{Chapter}
\chapter{Title}
text
\chapter{Another}
text
\appendix
\setupname{Appendix}
\chapter{Title}
text
\end{document}
该\setupname
命令可能集成在\mainmatter
和中\appendix
,但这留作练习。:)
答案2
在后面添加此行\begin{appendices}
:
\addtocontents{toc}{\def\protect\cftchappresnum{\appendixname{} }}
它会在 TOC 文件中添加一行来更改章节的标题(您应该运行两次)。您可能还想更改标签宽度,因此请在行中输入Appendix
而不是。Chapter
\AtBeginDocument...
答案3
tocloft
如果您不使用命令,则使用答案可以正常工作\include
。问题是,用于\addtocontents
将内容放入目录中的延迟写入机制通常在包含内容之后结束。在所有条件下都有效的解决方案是:
amsbook
(1)这是类的默认行为
(2)memoir
通过在序言中加入以下内容即可获得:
\renewcommand*{\cftpartname}{PART~}
\renewcommand*{\cftchaptername}{\chaptername~}
\renewcommand*{\cftappendixname}{\appendixname~}
\renewcommand*{\cftchapteraftersnum}{.}% dot after the number
\setlength{\cftchapternumwidth}{2em}
(3)使用标准book
类,你需要做很多修改。以下内容来自中远海运并成为最终的代码的基础memoir
\documentclass{book}
\makeatletter
%% Add a conditional to \appendix. Could also use \@chapp.
\newif\if@inappendix\@inappendixfalse
\let\oldappendix=\appendix
\renewcommand*{\appendix}{\oldappendix\@inappendixtrue}
%% User defined number width in TOC (\tocchpnumwdth)
%% Add inserts for Chapter and Appendix. Define to
%% \relax if standard output is needed.
\newlength{\tocchpnumwdth}
\setlength{\tocchpnumwdth}{1.5em}
\newcommand*{\tocchapinsert}{\chaptername\space}
\newcommand*{\tocappinsert}{\appendixname\space}
%% Small change in \@chapter. Write write different contents
%% line for Chapter and Appendix. Add inerts to \numberline.
\def\@chapter[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\if@inappendix
\addcontentsline{toc}{appendix}%<-- THIS IS NEW
{\protect\numberline{\tocappinsert\thechapter}#1}%<-
\else
\addcontentsline{toc}{chapter}%
{\protect\numberline{\tocchapinsert\thechapter}#1}%<-
\fi
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\chaptermark{#1}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
\if@twocolumn
\@topnewpage[\@makechapterhead{#2}]%
\else
\@makechapterhead{#2}%
\@afterheading
\fi}
%% Creates a \l@appendix identical to \l@chapter. Add the
%% width of the inserts to the width of the \numberline
%% box (\@tempdima).
\renewcommand*\l@chapter{\l@@chapter{\tocchapinsert}}
\newcommand*\l@appendix{\l@@chapter{\tocappinsert}}%<-- NEW
\newcommand*\l@@chapter[3]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\settowidth{\@tempdima}{#1}% <- change
\addtolength\@tempdima{\tocchpnumwdth}%<- change
\advance\leftskip\@tempdima
\hskip -\leftskip
#2\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #3}\par
\penalty\@highpenalty
\endgroup
\fi}
%% Keep hyperref happy
\def\toclevel@appendix{0}
\makeatother
\usepackage[breaklinks=true, % for long names
]{hyperref}
\begin{document}
\frontmatter
\chapter{Preface}
\tableofcontents
\chapter{Nomenclature}
\mainmatter
\chapter{First Chapter}
\section{First Section}
\appendix
\chapter{First Appendix}
\section{First Appendix Section}
\backmatter
\chapter{Data Tables}
\end{document}