4

Whenever I am using the following code

 \appendix
 \addcontentsline{toc}{chapter}{9 \enspace Appendices}
 \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}

to avoid listing individual appendices in the table of contents the list of figures (lof) disappears. I have checked removing the above command from the appendix the lof appears.

6

You have to restore the tocdepth counter after the appendix with \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}:

\documentclass{report}

\begin{document}
\tableofcontents
\listoffigures

\begin{figure}
  \caption{figure}
\end{figure}

\appendix
\addcontentsline{toc}{chapter}{9 \enspace Appendices}
\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
\chapter{Appendix chapter that is not listed in the TOC}
...
%<end of appendix>
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
\end{document}

Assuming that the appendix is the very end of your document (which might not be the case, so be careful here) you could patch the end of the document like

\let\oldenddocument\enddocument
\def\enddocument{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
  \oldenddocument}

Then the file

\documentclass{report}

\makeatletter
\g@addto@macro\appendix{%
  \addcontentsline{toc}{chapter}{9 \enspace Appendices}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}}
\let\ltx@enddocument\enddocument
\def\enddocument{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
  \ltx@enddocument}
\makeatother

\begin{document}
\tableofcontents
\listoffigures

\begin{figure}
  \caption{figure}
\end{figure}

\appendix
\chapter{Appendix chapter that is not listed in the TOC}
\end{document}

will yeld the same result as above. Note that there is also patching going on with \appendix to keep the document body clean:

\g@addto@macro\appendix{%
  \addcontentsline{toc}{chapter}{9 \enspace Appendices}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}}

This should be done anyways. Finally if the appendix is not the concluding part of the document one might consider to wrap the appendix into an environment in order to have an end marker, hence an appropriate place to hook into (e.g. with the instruction \def\endappendix{\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}}) and then say

\documentclass{book}

\makeatletter
\g@addto@macro\appendix{%
  \addcontentsline{toc}{chapter}{9 \enspace Appendices}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}}
\def\endappendix{\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}}
\makeatother

\begin{document}
\tableofcontents
\listoffigures

\begin{figure}
  \caption{figure}
\end{figure}

\begin{appendix}
\chapter{Appendix chapter that is not listed in the TOC}
...
\end{appendix}

\backmatter
\chapter{After the appendix}
\end{document}

It should be noted that this is a change of the standard interface!

  • Thanks a lot! It works fine after restoring the tocdepth counter. – Physics Moron Jan 22 '17 at 13:33

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.