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.

Having code like this

\documentclass{article}
\usepackage{lipsum}
\usepackage{titletoc}
\begin{document}
\tableofcontents
\section{A long section}
\startcontents[section]
\printcontents[section]{}{2}{\setcounter{tocdepth}{3}}
\lipsum[1-2]
\subsection{SubA}
\subsubsection{SSub-a}
\subsection{SubB}
\subsubsection{SSub-b}
\subsection{SubC}
\end{document}

I want to skip sub- and subsubsections for section A long section in a main TOC but have them present in a section toc. Wrapping the section with \addtocontents{toc}{\setcounter{tocdepth}{1}} and \addtocontents{toc}{\setcounter{tocdepth}{3}} hides A long section's structure from main toc but makes it's own toc disappear completely. How can I get what I want?

share|improve this question

2 Answers 2

up vote 11 down vote accepted

By default, titletoc writes partial ToCs to a file with extension .ptc; you can then set the tocdepth counter to the appropriate values (for the main ToC using \addtocontents{toc}{...} and for the partial ToC using using \addtocontents{ptc}{...}.)

\documentclass{article}
\usepackage{lipsum}
\usepackage{titletoc}
\begin{document}
\tableofcontents
\addtocontents{toc}{\setcounter{tocdepth}{1}}
\section{A long section}
\startcontents[section]
\printcontents[section]{}{2}{\addtocontents{ptc}{\setcounter{tocdepth}{3}}}
\lipsum[1-2]
\subsection{SubA}
\subsubsection{SSub-a}
\subsection{SubB}
\subsubsection{SSub-b}
\subsection{SubC}
\addtocontents{toc}{\setcounter{tocdepth}{3}}
\end{document}

enter image description here

share|improve this answer
    
great! that's exactly what i wanted –  qdiesel Jun 16 '12 at 20:29
    
And would it be possible to have one global tableofcontents for the sections only, then one partial tableofcontents for the subsections only, and finally one partial tableofcontents for subsubsections only? –  pluton Aug 15 '13 at 3:52
    
@pluton yes; it's possible using \startcontents[...], \resumecontents[...]. Perhaps you could ask this in a new question? –  Gonzalo Medina Aug 15 '13 at 14:02

In response to my own comment on Gonzalo's post, a slight modification to his solution works with the mathtools and mhchem package:

\startcontents[section]
\printcontents[section]{}{2}{\setcounter{tocdepth}{3}}

Note the only change from the MWE above is that I have removed \addcontents{ptc} and the extra set of curly braces from setcounter in the \printcontents command.

I have used this solution both in an article and a book documentclass with no problems.

share|improve this answer

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.