How to make a local TOC that only shows levels below where it is inserted?

I simply want to make a local Table of Contents (TOC) which shows in its content what is below the level the TOC is inserted in and not outside.

For example, if I do \minitoc inside \section{}, the local TOC should only show the subsections and subsubsection inside this section.

Similarly, if I do \minitoc inside \subsection{}, the local TOC should only show the subsubsections inside this section.

But a TOC inside, say, a subsection, will show everything starting from the section above, to the end of the document! Which is very confusing.

I'll show an MWE and then show what I want:

\documentclass{report}
\usepackage{minitoc}
\setcounter{secnumdepth}{5}
\begin{document}

\dominitoc
\setcounter{tocdepth}{1} %For the main TOC, only show chapter/section
\tableofcontents

\setcounter{minitocdepth}{5}
\minitoc %This TOC should only show the two subsubsection below!

\subsection{this is yet another subsection heading}

\section{this is yet another section}
\end{document}


The idea is the the local TOC should only show what is in the lower level and no more. It acts as a guide of what is inside that section or subsection.

This way, I can make a local TOC in each section or subsection, which only shows what is below it, and it gets cut off when the level goes up automatically.

I hope there is a simple solution for this. I am open to others solutions using etoc or something else as long as the local TOC only shows what is inside that level as described above.

I tried to use this answer, but I do not understand the answer (too complicated for me) and how to use it for the above example. This is what I tried:

\documentclass{report}
\usepackage{minitoc}
\usepackage{etoc}
\setcounter{secnumdepth}{5}
\begin{document}
%\dominitoc %Removed. switch to etoc
\setcounter{tocdepth}{1} %For the main TOC, only show chapter/section
\tableofcontents

%\setcounter{minitocdepth}{5} %Do not use now, we are using etoc
\localtableofcontents

\subsection{this is yet another subsection heading}
\section{this is yet another section}
\end{document}


I get this:

Which is not what I want. If someone knows how to implement the solution shown in here for my small example above, it will be great. Again, I am not asking for fancy heading, fancy line styles, minipages, and all that. A simple local TOC is all I want.

• See tex.stackexchange.com/q/87709/27635. I don't think minitoc can manage this. – karlkoeller Jan 2 '15 at 20:43
• @karlkoeller I actually saw the question you linked to, spend 2 hrs just trying to understand it and could it. If things has to be this complicated to make local toc in latex, then something is wrong here. I did not undertand all this \makeatletter \newif\ifTOC@marginpatched \newcommand{\SetTOCrightmargin}[1]{% \ifTOC@marginpatched\else \let\old@pnumwidth\@pnumwidth \let\old@dottedtocline\@dottedtocline \def\@dottedtocline##1##2##3##4##5{% \old@dottedtocline{##1}{##2}{##3}{##4}{##5\hskip\TOC@rightmargin}} \let\old@l@part\l@part \def\l@part##1##2{\old@l@part{##1}{##2\hskip\TOC@rightmar.. – Nasser Jan 2 '15 at 20:47
• I need a simple solution that I can understand. Not asking for anything fancy. All solutions posted seems to be too complicated for some reason. May be it is the nature of Latex. – Nasser Jan 2 '15 at 20:48

The etoc package provides for a \localtableofcontents which can be configured in place with \etocsettocstyle and etocsetnexttocdepth commands

The visual appearance can be configured with tocloft commands.

\documentclass{report}
\usepackage{tocloft}
\usepackage{etoc}
\setcounter{secnumdepth}{4}
\begin{document}

\setcounter{tocdepth}{1} %for main TOC, only show chapter/section
\tableofcontents
\etocsetnexttocdepth{5}
\etocsettocstyle{\subsubsection*{Local contents}}{}
\cftsubsubsecindent 0pt
\localtableofcontents

\subsection{this is another subsection heading} % not shown
\subsection{this is yet another subsection heading} % not shown
\section{this is yet another section} %not shown
\end{document}


• another nice solution, thank you. Simple direct solution. – Nasser Jan 2 '15 at 21:40
• The \etocsetlevel{subsection}{1} line is not needed. I would suggest also inserting for example \etocsettocstyle{\subsubsection*{\contentsname{} for this subsection}}{} right before the \localtableofcontents. – user4686 Jan 2 '15 at 22:35
• The reason for the big left indentation is because this is inherited from how the subsubsections headings would be displayed by the document class. Package tocloft can be loaded for easy customizing of this. Just make sure it is loaded before etoc. It is also possible to use etoc for all the customizing one wishes, but this is admittedly harder on the standard user. – user4686 Jan 2 '15 at 22:39
• @ChristianHupfer with \usepackage{tocloft} in the preamble and simply \cftsubsubsecindent 0pt  on a line before the \localtableofcontents the indentation is gotten rid of. – user4686 Jan 2 '15 at 22:47
• I counted @Nasser then Christine who supervised the translation into German of etoc.pdf, then at least one member of her team, but I might be too optimistic ;-) – user4686 Jan 3 '15 at 23:12

I'm a big fan of titletoc instead of minitoc, (especially since I use titlesec all the time) and titletoc provides easy methods to do what you want.

\documentclass[]{book}
\usepackage[margin=1in]{geometry} % just to make a nice image for the answer
\usepackage{titletoc}
\usepackage{lipsum}
\begin{document}
\tableofcontents
\chapter{A chapter}
\startcontents[chapters]
\printcontents[chapters]{}{1}{}
\section{Section}
\startcontents[sections]
\printcontents[sections]{}{1}{}
\subsection{Subsection 1}
\lipsum[1]
\stopcontents[sections]
\section{Section 2}
\startcontents[sections]
\printcontents[sections]{}{1}{}
\subsection{Subsection 1}
\lipsum[2]
\subsection{Subsection 2}
\lipsum
\stopcontents[sections]
\chapter{Second chapter}
\startcontents[chapters]
\printcontents[chapters]{}{1}{}
\section{Section}
\startcontents[sections]
\printcontents[sections]{}{1}{}
\lipsum[3]
\section{Another section}
\lipsum
\end{document}