Choose singular or plural form of Appendix in the subappendices environment

by WZhao   Last Updated September 11, 2019 09:23 AM - source

I am using subappendices environment from appendix package to add appendices at the end of each chapter. What I want is to choose singular or plural form of Appendix in the ToC based on the number of sections in the appendix part. The figures and tables also need to be added in the ToC.

I tried the solution in here. But, he forgot to add the figures and tables in the appendix to the ToC.

MWE

\documentclass[11pt, a4paper, twoside]{book}
\RequirePackage[title,titletoc]{appendix}
\usepackage{etoolbox}
\AtBeginEnvironment{subappendices}{%
\section*{Appendix}
\addcontentsline{toc}{section}{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{First section}
\section{A subsection}

\begin{subappendices}
\section{First appendix}
\end{subappendices}

\chapter{Second section}
\section{A subsection}

\begin{subappendices}
\section{First appendix}
\section{Second appendix}
\end{subappendices}

\end{document}


Related Questions



Remove appendix page numbers in TOC

Updated April 15, 2015 21:10 PM


Add a chapter and the bibliography to the maintoc

Updated June 20, 2015 23:10 PM

How to have separate list of Appendix figures?

Updated January 27, 2017 14:09 PM