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

Tags :