DocumentClass-Independent Table of Contents (eToC)

etocminitoctocloft

I want to create a local table of contents, and am currently using etoc. I noticed that the formatting is largely dependent of the documentclass.
Below is a screenshot for the article document class result of \localtableofcontents.
Article document class etoc

and the \localtableofcontents for the report documentclass enter image description here

My LaTeX needs to be written in the article document class but I would really to make the formatting of the local toc to match the report document class. More specifically the smaller gaps between lines and the …….. before page numbers.

I've scanned through the documentation for etoc and it's filled with complex macros that I'm having difficulty manipulating to get the desired result.

Here's a MWE

\documentclass{report}
\usepackage{etoc}

\title{Report Doc Class}
\begin{document}
\maketitle

    \localtableofcontents

     \section{first section (of report doc class)}

     \section{second section}

     \section{third section}
\end{document}

I'm also curious if there's any strong preferences for etoc vs tocloft vs minitoc etc. for local table of contents. Thank you 🙂

Best Answer

Use the tocloft package. I have taken your MWE, for which thanks, changed it to the article class and added tocloft code to tweak the local ToC to what you say you want.

EDIT I have changed the MWE to unbold the ToC entries as asked for in a commment by the OP. I have not changed the graphic to match which shows the original bold entries.

% etocprob2.tex  SE 622703

\documentclass{article} %\documentclass{report}
\usepackage{tocloft}  % must be before etoc package
\renewcommand{\cftsecdotsep}{\cftdotsep} % add dots to section entries
\setlength{\cftbeforesecskip}{0pt} % no extra vertical space between section entries
\renewcommand{\cftsecfont}{} % normal (non-bold) font for section entries
\renewcommand{\cftsecpagefont}{} % normal font for section pages

\usepackage{etoc}

%\title{Report Doc Class}
\title{Article Doc Class}
\begin{document}
\maketitle

%\tableofcontents

   \localtableofcontents

     \section{first section (of article doc class)}

     \section{second section}

     \section{third section}
\end{document}

enter image description here

Related Question