Anhang nach jedem Kapitel v2.0

Anhang nach jedem Kapitel v2.0

Ich bin daran interessiert, nach jedem Kapitel in einem Buch einen Anhang mit zwei oder drei Abschnitten hinzuzufügen, genau wie in der beantworteten FrageHier.

Die dort bereitgestellte Antwort funktioniert gut, hat aber unerwünschte Auswirkungen auf die Nummerierung von Abbildungen usw. In der bookKlasse werden Abbildungen kapitelspezifisch nummeriert (z. B. 1.1, 1.2, ..., 2.1, 2.2), was mir gefällt. Die Antwort setzt dies jedoch auf abschnittsspezifische Nummerierung in allen Kapiteln zurück, nachdem die neue subappendicesUmgebung verwendet wurde, was zu einer seltsamen abschnittsspezifischen Nummerierung führt - 1.1, 1.2 (Kapitel 1 gut), Unteranhänge, 2.1, 2.2 (Abbildungen von Kapitel 2 im ersten Abschnitt), 2.1, 2.2 (Abbildungen von Kapitel 2 im zweiten Abschnitt). Wie kann man die Nummerierung auf kapitelspezifisch zurücksetzen?

Hier ist das 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}

Antwort1

Was gut funktioniert hat, ist, das Ende der subappendicesUmgebung wie folgt zu definieren

\AtEndEnvironment{subappendices}{%
\counterwithout{figure}{section}
\counterwithin{figure}{chapter}
\counterwithout{table}{section}
\counterwithin{table}{chapter}
}

Das vollständige Beispiel:

\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}

Antwort2

Ändern Sie diese beiden Zeilen

\counterwithin{figure}{section}
\counterwithin{table}{section}

Zu

\counterwithin{figure}{chapter}
\counterwithin{table}{chapter}

oder lassen Sie sie vollständig weg (dies ist die Standardeinstellung).

verwandte Informationen