每章後附錄 v2.0

每章後附錄 v2.0

我有興趣在一本書的每一章後面添加一個包含兩到三個部分的附錄,與問題答案相同這裡

那裡提供的答案效果很好,但它對數字編號等產生了不良影響book。答案使用新subappendices環境後,將其重設為所有章節中的特定於節的編號,這會產生奇怪的特定於節的編號- 1.1、1.2(第1 章好)、子附錄、2.1、2.2(第一節中的ch 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}

或完全忽略它們(這是預設)。

相關內容