[Tex/LaTex] How to make a local TOC that only shows levels below where it is inserted

minitoctable of contents

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                 
\chapter{this is chapter heading}

  \section{this is section heading}
    \subsection{this is subsection heading}
    \setcounter{minitocdepth}{5}
    \minitoc %This TOC should only show the two subsubsection below!

       \subsubsection{this is subsubsection heading}
       \subsubsection{this is another subsubsection heading}

    \subsection{this is another subsection heading}
    \subsection{this is yet another subsection heading}

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

Mathematica graphics

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.

Addition

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         

\chapter{this is chapter heading}    
  \section{this is section heading}
    \subsection{this is subsection heading}
    %\setcounter{minitocdepth}{5} %Do not use now, we are using etoc
     \localtableofcontents

       \subsubsection{this is subsubsection heading}
       \subsubsection{this is another subsubsection heading}

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

I get this:

Mathematica graphics

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.

Best Answer

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
\chapter{this is chapter heading}    
  \section{this is section heading}
  \subsection{this is subsection heading}
    \etocsetnexttocdepth{5}
    \etocsettocstyle{\subsubsection*{Local contents}}{}
    \cftsubsubsecindent 0pt
    \localtableofcontents
    \subsubsection{this is subsubsection heading}
    \subsubsection{this is another subsubsection heading}

    \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}

enter image description here

**Thanks to jfbu for his helpful comments **

Related Question