[Tex/LaTex] Adding appendix “chapters,” without sections, in table of contents

appendicestable of contents

I have a document with two appendices, and I would like the appendices to appear in the table of contents but without the sections of each appendix appearing. For example, I would like the table of contents to contain something like the following:

Appendices ................ 100
  A  First Appendix ....... 101
  B  Second Appendix ...... 110

Bibliography .............. 130

I've tried toying with the appendix package, but haven't been able to get the result I'd like. Any help would be most appreciated. Just for comparison, right now my code is

\begin{appendices}
    \chapter{First Appendix}
    \chapter{Second Appendix}
\end{appendices}

Using \usepackage[toc,page]{appendix} the table of contents looks like

Appendices  .............. 100

A  First Appendix ........ 101
   A.1  First section .... 101
   A.2  Second section ... 102

B  Second Appendix ....... 110
   B.1  First section .... 110
   B.2  Second section ... 113

Bibliography ............. 120

I apologize if this is a duplicate; I know there are several questions regarding appendices and the table of contents, but I didn't see any that were quite like my question.

Here is a complete example:

\documentclass{book}
\usepackage[toc,page]{appendix}

\begin{document}
\tableofcontents

\mainmatter
\chapter{First Chapter}

\begin{appendices}
  \chapter{First appendix}
  \section{First section}
  \section{Second section}

  \chapter{Second appendix}
  \section{First section}
  \section{Second section}
\end{appendices}

\bibliographystyle{amsalpha}
\addtotoc{Bibliography}{\bibliography{bibliography}}

\end{document}

Best Answer

You have to change the value of tocdepth just for the appendices. It's probably not necessary to reset it afterwards, since the appendices are at the end.

\documentclass{book}
\usepackage[toc,page]{appendix}

\begin{document}
\tableofcontents

\mainmatter
\chapter{First Chapter}

\section{First section}

\begin{appendices}
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
  \chapter{First appendix}
  \section{First section}
  \section{Second section}

  \chapter{Second appendix}
  \section{First section}
  \section{Second section}
\end{appendices}
\end{document}

enter image description here

If you want that the appendices appear as if they were sections, you can change the meaning of \l@chapter and of \l@section in the same vein:

\documentclass{book}
\usepackage[toc,page]{appendix}

\begin{document}
\tableofcontents

\mainmatter
\chapter{First Chapter}

\section{First section}

\begin{appendices}
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\makeatletter
\addtocontents{toc}{%
  \begingroup
  \let\protect\l@chapter\protect\l@section
  \let\protect\l@section\protect\l@subsection
}
\makeatother
  \chapter{First appendix}
  \section{First section}
  \section{Second section}

  \chapter{Second appendix}
  \section{First section}
  \section{Second section}
\addtocontents{toc}{\endgroup}
\end{appendices}

\backmatter

\chapter{Bibliography}

\end{document}

I used \backmatter and \chapter{Bibliography} just to show the result. Use your own method.

enter image description here