# How to only show \addcontentsline words in TOC

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):

• you might find this answer helpful: Is it possible to remove specific section page number in TOC without losing page numbers for its subsections?. that method is rather complicated. an alternative is to use the command \addtocontents (instead of \addcontentsline) and leave the page number field empty. (you haven't given enough information to be more specific; look for documentation of the \addtocontents command.) – barbara beeton Oct 12 '16 at 14:42
• thanks for the comments. The suggestion and code below from jfbu below worked out to be the ideal solution. – user62494 Oct 13 '16 at 0:50

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}

\section {bar}


For more info see the etoc manual Arbitrary “Lists Of...”, \etoctoccontentsline
• 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