Choose singular or plural form of Appendix in the subappendices environment

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

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


Updated May 13, 2015 18:10 PM

Updated April 15, 2015 21:10 PM

Updated June 07, 2015 13:10 PM

Updated June 20, 2015 23:10 PM

Updated January 27, 2017 14:09 PM