I need to only show student names in the TOC, via using e.g. \addcontentsline{toc}{section}{name}. However, there are sections, subsections, and paragraphs, so the sections are being listed. There are no chapters, however. Is there a way to kill everything in a TOC except what is added via \addcontentsline{.}{.}{.}?

Since there are no chapters, I tried the following method to kill sections and below, and then hang the contents of \addcontentsline to the chapter environment:


and used within the text:


and below is the result (which, did not work):

enter image description here


It is not exactly clear how you intend to use your \addcontentsline but you can do something like this.




\newcommand\studentlist {%
  \etocsetlevel {student}{-1}%
  \etocsetnexttocdepth {student}%
  \etocsetlevel {part}{0}% make parts invisible
  \etocsetstyle {student}
                {\noindent\textbf{\etocname}\nobreak\hrulefill page \etocpage\par}
  \etocsettocstyle{\section*{\Large\bfseries List of students}}{}%




\part {One}

\section {foo}

\addcontentsline {toc}{student}{John Doe}
\addcontentsline {toc}{student}{Andrew Doe}
\addcontentsline {toc}{student}{Emily Doe}

\section {bar}

\addcontentsline {toc}{student}{Hillary Doe}
\addcontentsline {toc}{student}{Chelsea Doe}
\addcontentsline {toc}{student}{Marie Doe}


enter image description here

For more info see the etoc manual Arbitrary “Lists Of...”, \etoctoccontentsline

  • Thanks - this worked very nicely - and it looks terrific! – user62494 Oct 13 '16 at 0:50
  • good ;-) please do read section referred to in etoc manual. Particularly perhaps you want \etoctoccontentsline{student}{John} rather than \addcontentsline{toc}{student}{John}, in case you use hyperref and do not want the students to appear in the pdf bookmarks. – user4686 Oct 13 '16 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy