我在每一章后都使用附录或附录,如下:这个帖子。这是我使用的 Latex
\usepackage[toc,page]{appendix}
\AtBeginEnvironment{subappendices}{%
\chapter*{Appendix}
\addcontentsline{toc}{chapter}{Appendices}
\counterwithin{figure}{section}
\counterwithin{table}{section}
}
例如,其结果如下:
但是,附录的标题没有编号。理想情况下,它们及其部分应该有基于该编号的编号。我的想法是这样的:
3. Chapter Three
3.1 Intro
3.2 Some details
3.3 Experiments
3A. Appendix
3A.1 First subappendix of chapter 3
3A.2 More details etc
有办法实现这个吗?
答案1
您可以修改早期帖子中的代码,以便:
- 将“\thechapter A\quad”(或类似内容)添加到 \chapter*{...}
- 方便地添加 \addcontentsline 将“\thecahpter A”添加到目录中的附录中
- 修改 \thesection 以打印“A”。
这是通过以下方式完成的:
\AtBeginEnvironment{subappendices}{%
\chapter*{\thechapter A\quad\appendixname}
% add \numberline{<num-chap>A} to toc
\addcontentsline{toc}{chapter}{%
\protect\numberline{\thechapter A}\appendixname}
\counterwithin{figure}{section}
\counterwithin{table}{section}
}
% make section display <num-chap>A.<num-sec>
\apptocmd{\subappendices}{%
\renewcommand{\thesection}{\thechapter A.\arabic{section}}}{}{}
然而,我们发现新的附录编号(如 1A.2)比以前的编号(如 1.B)要长,并且目录中的数字与标题太接近,如下所示:
因此您可以增加这些间隙。在您的类文件(此处)中查找 \l@chapter 和 \l@section 的代码book.cls
并更改间距,如下所示:
\makeatletter
% in \l@chapter change 1.5em by 2em
\patchcmd{\l@chapter}{1.5em}{2em}{}{}
% in \l@section change {1.5em}{2.3em} by {2em}{2.8em}
\renewcommand*\l@section{\@dottedtocline{1}{2em}{3em}}
\makeatother
完整代码:
\documentclass{book}
\usepackage{appendix}
\usepackage{chngcntr}
\usepackage{etoolbox}
\usepackage{lipsum}
\AtBeginEnvironment{subappendices}{%
\chapter*{\thechapter A\quad\appendixname}
% add \numberline{<num-chap>A} to toc
\addcontentsline{toc}{chapter}{%
\protect\numberline{\thechapter A}\appendixname}
\counterwithin{figure}{section}
\counterwithin{table}{section}
}
% make section display <num-chap>A.<num-sec>
\apptocmd{\subappendices}{%
\renewcommand{\thesection}{\thechapter A.\arabic{section}}}{}{}
\makeatletter
% in \l@chapter change 1.5em by 2em
\patchcmd{\l@chapter}{1.5em}{2em}{}{}
% in \l@section change {1.5em}{2.3em} by {2em}{2.8em}
\renewcommand*\l@section{\@dottedtocline{1}{2em}{3em}}
\makeatother
\begin{document}
\tableofcontents
\chapter{Test Chapter One}
\section{A regular section}
\section{Another regular section}
\begin{subappendices}
\section{Some title for an appendix}
\lipsum[4]
\section{Some title for an appendix}
\lipsum[4]
\end{subappendices}
\chapter{Test Chapter Two}
\section{A regular section}
\section{Another regular section}
\begin{subappendices}
\section{Some title for an appendix}
\lipsum[4]
\section{Some title for an appendix}
\lipsum[4]
\section{Some title for an appendix}
\lipsum[4]
\end{subappendices}
\end{document}