2

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:

\setcounter{tocdepth}{0}
\tableofcontents

and used within the text:

\addcontentsline{toc}{chapter}{name}

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

enter image description here

2
0

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

\documentclass{article}

\usepackage{etoc}

\etocsetlevel{student}{6}

\newcommand\studentlist {%
  \begingroup
  \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}}{}%
  \tableofcontents
  \endgroup
}

\begin{document}

\tableofcontents

\studentlist

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

\end{document}

enter image description here

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

2
  • 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