Skip to main content

Tables of Contents

by Andrew Roberts

If you write long reports, manuals, books, theses and so on, it's standard practice to add tables of contents (perhaps also tables of figures and tables of tables too) and depending on the type of document you may require an index too. LaTeX has all the facilities for these classic requirements and this tutorial will guide you through them.

Tables of Contents

A table of contents typically sits at the beginning of a large manuscript and lists all the chapters and sections within along with a page number. It pains me to recall but I've actually seen people write such tables by hand. I recall a close friend helping another friend with an MSc dissertation written in Microsoft Word. Although Word comes with the features to automatically generate the tables, it is rather temperamental and wasn't playing ball. It's not so much the issue of gathering all the section headings that is tedious, but logging the page reference, for if you make a subsequent alteration to the main text, you risk having to rescan the entire document to update them! And it was exactly this kind of business that I witnessed my friend going though (to be fair, I've used Word and its Table of Contents functionality did work flawlessly - other times it didn't though!)

Anyway, you'll be pleased to know that adding tables of contents is very straightforward. The reason being is that you will have done all the 'hard work' in advance by marking up all the headings with various section commands (\chapter{}, \section{}, etc). All LaTeX needs to do is harvest all the headings from your document as it processes it. Basically, all you need to do is to tell LaTeX that you actually want the TOC to appear (a bit like how you need to tell it to show the document title information with \maketitle.

All you need to do is add the following command at the point in the document where the TOC is expected to appear (somewhere in-between the title and the content):

\tableofcontents

I've created a sample 'book' to illustrate this topic. It merely consists of the first two Getting to Grips with LaTeX tutorials as chapters. Look at the before and after versions of this document to see what happens once the \tableofcontents command is employed:

TOC Counter Depth

As happy as you may be with the results (especially given the relatively little effort) there are often things that one may wish to tweak, and the counter depth is perhaps the most common. By default LaTeX TOCs will display to the third level (which is subsection for the book class, or subsubsection in the article class), so we see 1.1.1 in the sample book.

To alter this, use the \setcounter command: \setcounter{tocdepth}{depth}

\setcounter{tocdepth}{1}
default table of contents as typeset by LaTeX table of contents constrained to a section depth of 1
Original tocdepth=1

Other built-in tables/lists

It's often the case in academic manuscripts, such as theses and text books a List of Tables and List of Figures accompany the Table of Contents. LaTeX also provides convience commands to issue the production of such lists.

\listoffigures
\listoftables
Are all you need to type in order to have these lists automatically generated. It should be obvious, however, that these commands are looking for instances of the figure and table environments.

Adding lines to tables of contents

Whilst \tableofcontents does a great job and takes care of an awful lot of tedious work, there are times when its results are not sufficient. A common reason is when the starred (*) form of a sectioning command was used, which not only omits any section numbering, it is also omitted from the TOC. If you wish to reinstate a line, then the command use is \addcontentsline{type}{section_level}{entry}, where:

  • type - can be toc, lof, lot depending on whether the line is to appear in the Table of Contents, List of Figures or List of Tables respectively.
  • section_level - here is where you input at what level the line is to be assigned, e.g., chapter, section, subsection, etc.
  • entry - the actual text to appear in the line.
An example of its use would be:
\addcontentsline{toc}{section}{Preface}
Finally, you should place the command at the appropriate location of the section/figure/table in your document in order for it to be extracted in the correct order.

Indexes

[PENDING]