0

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.

A MWE is shown below which always shows "Appendices" in TOC and "Appendix" in the content.

\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 % always show "Appendices" in TOC and "Appendix" in the content
\listoffigures
\listoftables

\chapter{First chapter}
\section{A section}

\begin{subappendices}
\section{First appendix}

\begin{table}[h!]
  \begin{center}
    \caption{A simple table.}
    \label{tab:table1}
    \begin{tabular}{l|c|r}
      Value 1 & Value 2 & Value 3\\
      \hline
      1 & 1110.1 & a\\
      2 & 10.1 & b\\
    \end{tabular}
  \end{center}
\end{table}

\end{subappendices}

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

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

\end{document}

enter image description here

The MWE of @Mico 's approach is shown below which lacks the figures and tables in the appendix in the List of Figures and List of Tables.

Update: I am sorry for my mistake. The figures and tables in the appendix are not missing from the List of Figures and List of Tables. They are used a continuous numbering instead of a separate numbering in the previous MWE.

Mico's approach still works.

\documentclass[11pt, a4paper, twoside]{book}
\RequirePackage[title,titletoc]{appendix}

% Mico's approach in https://tex.stackexchange.com/a/47011/87806
\usepackage{ifthen}
\makeatletter
%% For source of "@seccntformat" command, see book "The LaTeX Companion"
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\ \ }%  default
   {\csname #1@cntformat\endcsname}}%    enable individual control
%% Individual control: '\section@cntformat'
\newcommand{\section@cntformat}{\thechapter.\thesection\ \ }

% Macros to redefine numbering of appendix sections
\newcommand{\appname}{} % dummy definition 
\newcommand{\appsecnumbering}[1][0]{%
    \ifthenelse{#1=1}{\renewcommand\appname{Appendix}}
                     {\renewcommand\appname{Appendices}}
    \setcounter{section}{0}
    \renewcommand\thesection{\thechapter.\Alph{section}}
    \renewcommand{\section@cntformat}{\appendixname~\thesection\ \ }
    \addtocontents{toc}{\medskip\protect{\mdseries\appname\par}}}
\newcommand\normalsecnumbering{%
    \renewcommand{\thesection}{\thechapter.\arabic{section}}
    \renewcommand{\section@cntformat}{\thesection\ \ }}
\let\origchapter\chapter
\renewcommand\chapter{\normalsecnumbering % first, reset numbering style
    \origchapter} % second, execute the original \chapter command
\makeatother

\begin{document}
\tableofcontents
\listoffigures
\listoftables

\chapter{First chapter}
\section{A section}

\appsecnumbering[1]
\section{First appendix}

\begin{table}[h!]
  \begin{center}
    \caption{A simple table.}
    \label{tab:table1}
    \begin{tabular}{l|c|r}
      Value 1 & Value 2 & Value 3\\
      \hline
      1 & 1110.1 & a\\
      2 & 10.1 & b\\
    \end{tabular}
  \end{center}
\end{table}


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

\appsecnumbering[2]
\section{First appendix}
\section{Second appendix}

\end{document}

enter image description here

  • @Mico Sorry for the possible misunderstanding. In the previous MWE, the problem is that the singular and plural form of Appendix do not show correctly. In your approach, the figures and tables in the appendix are missing from the ToC. I added two MWE to show more clearly. – WZhao Sep 11 '19 at 14:00
  • 1
    @Mico I am really sorry for my mistake. When I tried your method, I did not check the PDF carefully and thought that the figures and tables in the appendix are missing in the List of figures and list of tables. Actually, they are there, but uses a continuous numbering instead of numbering separately in the appendix. I also wrongly described the question. I did not mean "ToC" but LoF and LoT instead. – WZhao Sep 11 '19 at 14:42
  • I'm glad the misunderstanding has been worked out. I will go ahead and delete my earlier comments. In return, please edit your query and drop incorrect (or, at least, confusing) claims about my answer from a long time ago does and does not do. Thanks. – Mico Sep 11 '19 at 14:46
  • @Mico This question is updated. However, I indeed find a problem of your solution. Could you take a look at the new question ? Sorry for the disturbance. – WZhao Sep 12 '19 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.