Wednesday, November 23, 2005

Adding to table of contents ( LaTeX)

Starred versions of the sectioning commands are not added to the table of contents by default, but they can be added using:

\addcontentsline{file}{type}{text}
file
This should be the extension of the file where the contents are written. So this will be toc for the table of contents, lof for the list of figures and lot for the list of tables.

type
This is the type of object you are adding to the contents. e.g. chapter, section, figure.

text
This is the text that should go in the contents.

For example, the bibliography is generated using a starred version of the \chapter command, so it doesn't get added to the table of contents. To add it to the table of contents, you can do

\addcontentsline{toc}{chapter}{\bibname}

The counter tocdepth controls the section level depth in the table of contents.

The report class file sets tocdepth to 2, which means that only the parts, chapters, sections and subsections will be entered into the table of contents. You can use \setcounter to change the value of tocdepth. For example, to also include the subsubsections, paragraphs and subparagraphs, do:

\setocounter{tocdepth}{5}