15

Sections in an appendix should look like

A.1 Name of the first section
A.2 Name of the second section

while in ToC should be only displayed

A name of appendix A

Using \section*{Name of the first section} doesn't work as it affects numbering within an appendix.

\documentclass[a4paper,12pt,titlepage,oneside,final]{book}
\usepackage[english]{babel}

\begin{document}
\tableofcontents

\appendix
\chapter{Name of appendix A}
\section*{Name of the first section}
\section{Name of the second section}

\end{document}

2 Answers 2

14

Without any additional package, this can be done by adding the following line just after the \appendix command:

\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}

MWE:

\documentclass[a4paper,12pt,titlepage,oneside,final]{book}
\usepackage[english]{babel}

\begin{document}
\tableofcontents

\appendix
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}} 
\chapter{Name of appendix A}
\section{Name of the first section}
\section{Name of the second section}

\end{document} 

Output

enter image description here

4
  • 5
    This somehow empties my "List of Figures". How do I fix that? Mar 3, 2018 at 16:07
  • 1
    @DavidNathan Either use \protect\value{tocdepth}=0 instead of \protect\setcounter{tocdepth}{0} or add something like \setcounter{tocdepth}{1} after \tableofcontents. Jan 10, 2019 at 6:48
  • @Schweinebacke sorry for this reply. I wonder why \value{tocdepth}=0 works but \setcounter{tocdepth}{0} doesn't.
    – Syvshc
    May 19, 2022 at 8:22
  • After reading source2e.pdf, I found that \setcounter makes counter change globally: \global\csname c@#1\endcsname#2, and \value is local. My question is solved.
    – Syvshc
    May 19, 2022 at 8:36
6

You can use the tocvsec2 package to change the ToC depth at the desired location:

\documentclass[a4paper,12pt,titlepage,oneside,final]{book}
\usepackage[english]{babel}
\usepackage{tocvsec2}
\begin{document}
\tableofcontents

\appendix
\chapter{Name of appendix A}
\settocdepth{chapter}

\section{Name of the first section}
\section{Name of the second section}

\chapter{Name of appendix B}


\section{Name of the first section}
\section{Name of the second section}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .