0

I am writing a thesis, which contains appendices with different sections.

PROBLEM: The sections of the Appendices are visible on the "Content" page because it considers Appendix as a normal chapter which has many sections.

I am not sure if it correct to show the sections of the Appendix on the TOC page.

Please suggest, how can I hide the section details of Appendix on the TOC page.

  • 2
    try \appendix \addtocontents{toc}{\protect\setcounter{tocdepth}{0}} – touhami Oct 31 '15 at 9:37
  • @touhami: In case there is more details on the class I would suggest to post an answer. – user31729 Oct 31 '15 at 9:40
  • @ChristianHupfer as you say. – touhami Oct 31 '15 at 9:59
  • Skm: Auf deutsch: Ich würde mal ein paar Antworten zu einigen Fragen akzeptieren, da gibt es durchaus Möglichkeiten;-) -- das zeigt den Respekt gegenüber den Leuten hier, die einige Zeit investieren. – user31729 Oct 31 '15 at 10:27
  • @ChristianHupfer: I totally understand your point. But I cannot accept an answer that has not solved the problem because it will mislead people in future. Whenever an answer has helped and proved to be correct, I have always accepted it along with a Thanks note. :) – skm Oct 31 '15 at 11:14
2

If the appendix sections shouldn't be numbered → use \section*

Otherwise hide the sections with a special trick:

Since the tocdepth counter is important for LaTeX to decide which structuring level appears in the ToC it's enough to say \setcounter{tocdepth}{0} written to the ToC file. 0 stands for chapter level, which is above section so only chapters or parts would be written to the ToC, since chapters aren't available in a standard class, there's nothing written at all.

I've added a \ifhideappendixstuffintoc switch which does hide the appendix sections based on a condition.

enter image description here

\documentclass{article}

\newif\ifhideappendixstuffintoc

\hideappendixstuffintoctrue % yes, hide it! 

\makeatletter
\let\latex@@apendix\appendix % Store the original \appendix command

\renewcommand{\appendix}{%
  \latex@@appendix%
  \ifhideappendixstuffintoc
  \addtocontents{toc}{\protect\setcounter{tocdepth}{0}}% \protect is not really necessary, otherwise it will show \global \c@tocdepth 0\relax in the ToC file
  \fi
}
\makeatother

\begin{document}
\tableofcontents
\section{Main part section}
\clearpage
\appendix
\section{Section in Appendix}
\end{document}

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.