# Numbered section hidden from the ToC

I'm writing a set of course notes that has an appendix containing many activities.

I do not wish the activities to be shown in the Table of Contents, but I do wish them to be numbered. Here is the solution I was using:

In the preamble:

\newcommand{\activity}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}


and now my "activity" starts out with:

\newpage
\activity\section{A Fun Educational Activity}


There is only one problem. The activity starts out indented, as opposed to not indented, as a section should be.

How do I make my activity start out without an indent?

I realize I could simply add \noindent but it seems to me that there should be a more elegant solution.

-

Adjust the tocdepth counter, but only for the appendix.

\documentclass{article}

\begin{document}

\tableofcontents

\section{bla}

\section{blubb}

\appendix

\section{foo}

\section{bar}

\end{document}


EDIT: The tocdepth counter stands for "[t]he level number of the least significant sectional unit listed in the table of contents" (Lamport, LaTeX: A document preparation system, p. 176). Its default value is 3 for the article class (i.e., everything down to \subsubsection will make it into the ToC), 2 for book and report.

EDIT2: Stefan correctly points out in his answer that "[m]odifying tocdepth within the table of contents may affect the following list of tables or list of figures, if present". Here's a solution that doesn't involve using additional packages:

\documentclass{article}

\begin{document}

\tableofcontents

\listoffigures

\section{bla}

\section{blubb}

\begin{figure}[ht]
\centering
(Figure content)
\caption{A figure}
\end{figure}

\appendix

\section{foo}

\section{bar}

\begin{figure}[ht]
\centering
(Figure content)
\caption{An appendix figure}
\end{figure}

\end{document}

-
Nice solution!! – Bart Snapp Apr 25 '11 at 19:35

Modifying tocdepth within the table of contents may affect the following list of tables or list of figures, if present.

The package tocvsec2 provides ways for changing the depth of the TOC within the document body. For example, use

\maxtocdepth{section}


at the beginning of the document and

\settocdepth{part}


at the beginning of the appendix.

-