[Tex/LaTex] Specify minitoc for each chapter

etocminitoctable of contents

To specify the toc depth of each chapter I can do

\chapter{Title}
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
...
\chapter{Title}
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
...

How can I do this for the minitoc? Setting the minitocdepth counter does not seem to work.

Best Answer

Answer from 2013

(slightly rearranged for readability, and with a more complete code sample starting with \documentclass and ending with \end{document})

With the etoc package, you generate minitoc's with the command \localtableofcontents. You can modify the tocdepth counter before this command.

It is better (except if intentional) to avoid using addtocontents to inscribe some tocdepth changing instruction to the .toc file: indeed this will impact all the tables of contents inside the document.

Here is the code, to illustrate how one can modify the tocdepth counter in the document at the location where the TOCs are inserted.

Sorry if I am off-topic as I couldn't tell if minitoc was a specific reference to the minitoc package.

\documentclass{book}
\usepackage{etoc}
\begin{document}

\setcounter{tocdepth}{2}% down to subsections in main TOC
\tableofcontents

% redefine the headings of the future TOCs to use \section* rather than \chapter*
\etocarticlestyle

\chapter{Vincere}
\setcounter{tocdepth}{1}% local TOC displays only sections
\localtableofcontents

\section {Section 1}
\subsection {1.a}
\subsection {1.b}

\section {Section 2}
\subsection {2.a}
\subsection {2.b}

\chapter{Vincere ancora}
\setcounter{tocdepth}{2}% local TOC again displays sections and subsections
\localtableofcontents

\section {Section 3}
\subsection {3.a}
\subsection {3.b}

\section {Section 4}
\subsection {4.a}
\subsection {4.b}

\end{document}

Update in 2O15

A few months after this answer was posted in 2013, etoc got enriched with two new commands \etocsettocdepth and \etocsetnexttocdepth.

Package hyperref takes into account the local value of the tocdepth counter in its decision of what goes to the bookmarks (but see its option bookmarksdepth as documented in its README). It is thus advisable to use \etocsetnexttocdepth whose effect extends only to the typesetting of the next TOC be it local (\localtableofcontents) or global.

The \etocsettocdepth{<level>} should be used once in the preamble or near the beginning of the document to set the tocdepth counter to a given value. The <level> may be numeric or a name.

The \etocsetnexttocdepth{<level>} is for temporarily setting the tocdepth counter to a value only for the time of typesetting a TOC. This way no impact on the global bookmarks occurs.

Here is thus how the code above can be written with etoc 1.07g [2013/10/13] or later, in a way which avoids any disturbance of the global hyperref bookmarks:

\documentclass{book}
\usepackage{etoc}
\usepackage{hyperref}% for testing
\begin{document}

\etocsettocdepth{subsection}
% the main TOC goes down to subsections, and the bookmarks too.
\tableofcontents

% redefine the headings of the TOCs to use \section* rather than \chapter*
\etocarticlestyle

\chapter{Vincere}
\etocsetnexttocdepth{section}
% this local TOC goes down to sections, there is nil impact on bookmarks
\localtableofcontents

\section {Section 1}
\subsection {1.a}
\subsection {1.b}

\section {Section 2}
\subsection {2.a}
\subsection {2.b}

\chapter{Vincere ancora}
% this local TOC again displays down to subsections, like the main TOC
\localtableofcontents

\section {Section 3}
\subsection {3.a}
\subsection {3.b}

\section {Section 4}
\subsection {4.a}
\subsection {4.b}

\end{document}
Related Question