18

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}
14

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

  • @egreg Ok, I have tried this code. Several problems appear. Please take a look at: tex.stackexchange.com/questions/187205/… Thanks. – DavidC. Jun 29 '14 at 21:39
  • 1
    @egreg: This is a very nice solution. But in my PDF viewer (okular) the navigation bar does not list my appendices under the entry "Appendices" but rather on the same level. I guess this is due to the fact that every appendix is a \chapter. Do you have any idea how make them appear under the entry "Appendix"? (The ToC lists everything correctly, as in your example.) – eins6180 Nov 30 '15 at 14:37
  • @eins6180 Look at the documentation of the bookmark package. It's a new question, anyway. – egreg Nov 30 '15 at 14:40
  • @egreg: I didn't immediately see how the bookmark package could be of help. But I asked a new question here. Maybe you could have look? – eins6180 Nov 30 '15 at 17:16
  • This solution doesn't work well for me if I insert \includepdf[pages=1-,pagecommand={\thispagestyle{plain}},addtotoc={1,chapter,1,Statement,p1}]{statement} line before the following line: \addtocontents{toc}{\endgroup}. Statement is displayed as a B1 in the table of contents (C instead B1 is expected). – patryk.beza Mar 8 '17 at 13:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.