TransWikia.com

How to only show addcontentsline words in TOC

TeX - LaTeX Asked by user62494 on March 16, 2021

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

One Answer

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}

newcommandstudentlist {%
  begingroup
  etocsetlevel {student}{-1}%
  etocsetnexttocdepth {student}%
  etocsetlevel {part}{0}% make parts invisible
  etocsetstyle {student}
                {}
                {noindenttextbf{etocname}nobreakhrulefill page etocpagepar}
                {}
                {}%
  etocsettocstyle{section*{Largebfseries 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

Answered by user4686 on March 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP