如何让“附录”一词出现在目录中?现在目录看起来像这样:
1 ......
2 ......
.
.
A .....
B .....
我希望是:
1 ......
2 ......
.
.
Appendix A .....
Appendix B .....
我的latex源文件结构是这样的:
\begin{document}
\tableofcontents
\include{...}
\include{...}
\appendix
\include{...}
\include{...}
\end{document}
对于我的论文,我做了以下工作:
\appendix
\addcontentsline{toc}{section}{Appendix~\ref{app:scripts}: Training Scripts}
\section*{Sample Training Scripts}
\label{app:scripts}
Blah blah appendix content blah blah blah.
说明:我手动在目录中添加了一行,这样我的目录中就会显示“附录 X:...”。然后我使用星号从目录中排除了实际的部分命令。
有几种方法可以解决这个问题;不幸的是,现阶段我只能为您提供一个破解方案。一个问题是,如果我们重新定义节号“A”以包含“附录”一词,则会弄乱目录的格式。因此,我刚刚定义了一个新的分段命令,该命令打印不带编号的部分并手动插入“附录 X”。
有点难看,但至少它无需更改任何标记即可工作
:)
\documentclass{article}
\makeatletter
\newcommand\appendix@section[1]{%
\refstepcounter{section}%
\orig@section*{Appendix \@Alph\c@section: #1}%
\addcontentsline{toc}{section}{Appendix \@Alph\c@section: #1}%
}
\let\orig@section\section
\g@addto@macro\appendix{\let\section\appendix@section}
\makeatother
\begin{document}
\tableofcontents
\section{goo}
\label{a}
This is sec~\ref{a}
\section{har}
\label{b}
This is sec~\ref{b}
\appendix
\section{ji}
\label{c}
This is app~\ref{c}
\subsection{me}
does this look right?
\end{document}
附录包是非常好的和简单的解决方案。我的答案对于想要更改章节编号样式(例如使用西里尔字母或罗马数字)的人可能会有所帮助。附录编号样式在 \@resets@pp 命令中进行硬编码(我在此处查看了源代码http://hal.in2p3.fr/docs/00/31/90/21/TEX/appendix.sty)。我通过简单地将此命令重新定义为我自己的命令来解决它。只需将此代码添加到您的序言中即可:
\makeatletter
\renewcommand{\@resets@pp}{\par
\@ppsavesec
\stepcounter{@pps}
\setcounter{section}{0}
\if@chapter@pp
\setcounter{chapter}{0}
\renewcommand\@chapapp{\appendixname}
\gdef\thechapter{\Asbuk{chapter}} % changed
\else
\setcounter{subsection}{0}
\gdef\thechapter{\Asbuk{section}} % changed
\fi
\if@pphyper
\if@chapter@pp
\renewcommand{\theHchapter}{\theH@pps.\Asbuk{chapter}} % changed
\else
\renewcommand{\theHsection}{\theH@pps.\Asbuk{section}} % changed
\fi
\def\Hy@chapapp{\appendixname}%
\fi
\restoreapp
}
\makeatother
结果,
Appendix A
Appendix B
Appendix C
...
将更改为
Appendix A
Appendix Б
Appendix В
... etc
我不是乳胶专家,我不能保证这段代码不会破坏其他东西。
基于 @Will Robertson 的回答,下面的代码定义了相同的内容,但针对章节,并且还修复了使用
chapter*
包时 fancyhdr
不会添加到标题的事实。
通过序言中的内容,所有问题都得到解决。
\makeatletter
\newcommand\appendix@chapter[1]{%
\refstepcounter{chapter}%
\def\app@ct{Appendix \@Alph\c@chapter: #1}
\orig@chapter*{\app@ct}%
\markboth{\MakeUppercase{\app@ct}}{\MakeUppercase{\app@ct}}
\addcontentsline{toc}{chapter}{\app@ct}%
}
\let\orig@chapter\chapter
\g@addto@macro\appendix{\let\chapter\appendix@chapter}
\makeatother