4

I would like to add a table of contents inside a section environment to make a TOC made up of subsections, subsubsections and etc. One slight difficutly is that I am not using an article class document; its a customized one. I would use the article class if necessary. I would like something along the lines of:

\section{Section 1}
\tableofcontents
\subsection{Sub1}
\subsection{Sub2}

Thanks

3
  • Do you mean that the TOC inside the section should only display the contents of that particular section (and subsections), but not that of other sections? Dec 5, 2015 at 19:45
  • Yes, thats exactly what I want.
    – MJS
    Dec 5, 2015 at 20:03
  • 3
    perhaps \usepackage{etoc} and then use \localtableofcontents assuming your customized class hasn't its own handling of .toc file. Perhaps you will need \etocsetocstyle{}{} to not have a too big Contents printed.
    – user4686
    Dec 5, 2015 at 20:49

2 Answers 2

8

Thanks @jfbu. Your method worked for me. Here is my scrap code.

\documentclass{article}
\usepackage{etoc}



\begin{document}
\tableofcontents
\newpage

\section{Section 1}
\localtableofcontents
\subsection{Sub1}
\subsection{Sub2}

\newpage
\section{Section 2}
\localtableofcontents
\subsection{Sub1}
\subsection{Sub2}


\end{document}
1

You can also use titletoc to creat a local table of contents for each section.

\documentclass{article}
\usepackage{titletoc}

\begin{document}
\startcontents[subsections]
\stopcontents[subsections]
\section{Section 1}
\resumecontents[subsections]
\printcontents[subsections]{l}{1}[3]{}

\subsection{Sub1}
\subsection{Sub2}

\startcontents[subsections]
\stopcontents[subsections]
\section{Section 2}
\resumecontents[subsections]
\printcontents[subsections]{l}{1}[3]{}
    
\subsection{Sub1}
\subsection{Sub2}
    
\end{document}
1
  • Welcome to TeX.SE! Can you please complete your code snippet to be compilable for a fast proof of your solution?
    – Mensch
    May 8 at 14:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .