Приложение после каждой главы v2.0

Приложение после каждой главы v2.0

Мне интересно добавить приложение с двумя или тремя разделами после каждой главы в книге, как в ответе на вопросздесь.

Предоставленный там ответ работает хорошо, но он имеет нежелательный эффект на нумерацию рисунков и т. д. В 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}

или вообще не указывать их (это значение по умолчанию).

Связанный контент