我有兴趣在书的每一章后添加一个包含两到三个部分的附录,与问题答案中的一样这里。
那里提供的答案效果不错,但对图片编号等产生了不良影响。book
课堂上的图片按章节特定的方式编号(例如 1.1、1.2、...、2.1、2.2),我喜欢这种方式,但是答案在subappendices
使用新环境后,将其重置为所有章节中的章节特定编号,这会产生奇怪的章节特定编号 - 1.1、1.2(第 1 章好)、小附录、2.1、2.2(第一部分中的第 2 章图片)、2.1、2.2(第二部分中的第 2 章图片)。如何将编号重置为章节特定的编号?
以下是 MWE:
\documentclass{book}
\usepackage{appendix}
\usepackage{chngcntr}
\usepackage{etoolbox}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{float}
\AtBeginEnvironment{subappendices}{%
\chapter*{Appendix}
\addcontentsline{toc}{chapter}{Appendices}
\counterwithin{figure}{section}
\counterwithin{table}{section}
}
\begin{document}
\tableofcontents
\chapter{Test Chapter One}
\section{A regular section}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\section{Another regular section}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{subappendices}
\section{Some title for an appendix}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\section{Some title for an appendix}
\lipsum[4]
\end{subappendices}
\chapter{Test Chapter Two}
\section{A regular section}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\section{Another regular section}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\end{document}
答案1
效果很好的是将subappendices
环境的结束定义如下
\AtEndEnvironment{subappendices}{%
\counterwithout{figure}{section}
\counterwithin{figure}{chapter}
\counterwithout{table}{section}
\counterwithin{table}{chapter}
}
完整示例:
\documentclass{book}
\usepackage{appendix}
\usepackage{chngcntr}
\usepackage{etoolbox}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{float}
\AtBeginEnvironment{subappendices}{%
\chapter*{Appendix}
\addcontentsline{toc}{chapter}{Appendices}
\counterwithin{figure}{section}
\counterwithin{table}{section}
}
\AtEndEnvironment{subappendices}{%
\counterwithout{figure}{section}
\counterwithin{figure}{chapter}
\counterwithout{table}{section}
\counterwithin{table}{chapter}
}
\begin{document}
\tableofcontents
\chapter{Test Chapter One}
\section{A regular section}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\section{Another regular section}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{subappendices}
\section{Some title for an appendix}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\section{Some title for an appendix}
\lipsum[4]
\end{subappendices}
\chapter{Test Chapter Two}
\section{A regular section}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\section{Another regular section}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\begin{figure};
\begin{tikzpicture}; \draw (0,0) --(1,2);\end{tikzpicture}; \caption{some caption}
\end{figure}
\end{document}
答案2
改变这两行
\counterwithin{figure}{section}
\counterwithin{table}{section}
到
\counterwithin{figure}{chapter}
\counterwithin{table}{chapter}
或者完全忽略它们(这是默认设置)。