Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

Adjust the tocdepth counter, but only for the appendix.

\documentclass{article}

\begin{document}

\tableofcontents

\section{bla}

\section{blubb}

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

\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 
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
\addtocontents{lof}{\protect\setcounter{tocdepth}{0}}

\section{foo}

\section{bar}

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

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

\end{document}
share|improve this answer
    
Nice solution!! –  Bart Snapp Apr 25 '11 at 19:35
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.