Document Classesdifferent tocdepth for chapters in mainmatter

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
benti
Posts: 42
Joined: Fri Mar 06, 2009 4:51 pm

different tocdepth for chapters in mainmatter

Post by benti »

Hey all,

I have an \appendix which is part of my \mainmatter. I have set the normal tocdepth at 2; however, I don't want the countless sections and subsection of the appendix mentioned in the ToC, so there I need tocdepth 0.

How to do this? I tried resetting the tocdepth-counter just before the appendix, and that clearly doesn't work. Any other ideas?

best,
Niels

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

different tocdepth for chapters in mainmatter

Post by gmedina »

Hi,

the code below illustrates a possible solution. I defined the two commands \mysection and \mysubsection that behave like the standard \section and \subsection commands, but without generating entries in the ToC:

Code: Select all

\documentclass{book}

\makeatletter
\newcounter{mysection}[chapter]
\renewcommand\themysection{\thechapter.\@arabic\c@mysection}
\newcounter{mysubsection}[mysection]
\renewcommand\themysubsection{\themysection.\@arabic\c@mysubsection}
\newcommand\mysection{\@startsection {mysection}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries}}
\newcommand\mysubsection{\@startsection{mysubsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\large\bfseries}}
\newcommand*\l@mysection{\@dottedtocline{1}{0em}{0em}}
\newcommand*\l@mysubsection{\@dottedtocline{2}{0em}{0em}}
\makeatother

\begin{document}
\tableofcontents

\chapter{Test chapter one}
\section{Test section one one}
\subsection{Test subsection one one one}
\chapter{Test chapter two}
\section{Test section two one}
\subsection{Test subsection two one one}

\appendix
\chapter{Test Appendix}
\mysection[]{Test section in the appendix}
\mysubsection[]{Test subsection in the appendix}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply