Your support for our advertisers helps cover the cost of hosting, research, and maintenance of this document

Formatting Information — An introduction to typesetting with LATEX

Chapter 2: Basic structures

Section 2.8: Table of contents

All auto-numbered headings (parts, chapters, sections, subsections, etc) get entered in the Table of Contents (ToC) automatically. You don’t have to print a ToC, but if you want to, add the command \tableofcontents at the point where you want it printed (usually after the Abstract or Summary).

Entries for the ToC are recorded each time you typeset your document, and only reproduced the next time you typeset it, so you need to run LATEX an extra time to ensure that all ToC page-number references are correctly resolved. This should be done automatically by your editor as needed, whenever you click the Build, Compile, Typeset, or Make button or menu entry (see Figure 1.4).

The commands \listoffigures and \listoftables work in exactly the same way as \tableofcontents to automatically list all your tables and figures. If you use them, they normally go after the \tableofcontents command.

We’ve already seen in § 2.6 how to use the optional argument to the sectioning commands to add text to the ToC which is slightly different from the one printed in the body of the document. It is also possible to add extra lines to the ToC, to force extra or unnumbered section headings to be included.

Exercise 7: Using a Table of Contents

  1. Add the \tableofcontents command to your document, after the \maketitle command but before the Abstract.

  2. Typeset the document.

    If you are using your editor’s Build to typeset the document, it should re-run LATEX if necessary, to make sure the Table of Contents is updated to reflect any changes you have made (for example in section numbering, or adding, deleting, or moving sections or chapters around.

  3. If the Table of Contents does not reflect your document structure, you need to typeset it one more time, to bring it up to date.

The \tableofcontents command normally shows only numbered section headings, and only down to the level defined by the tocdepth counter (see § 2.6.1), but you can add extra entries with the \addcontentsline command. For example if you use an unnumbered section heading command to start a preliminary piece of text like a Foreword or Preface, you can write:


This will format an unnumbered ToC entry for ‘Preface’ in the ‘subsection’ style. You can use the same mechanism to add lines to the List of Figures or List of Tables by substituting lof or lot for toc.

There is also a command \addtocontents which lets you add any LATEX commands to the ToC file. For example, to add a horizontal rule and a 6pt gap, you could say


at the place where you want it to occur. You should probably only use this command once you know what you are doing.

There are several packages to help you restyle these lists of contents; perhaps the best-known is tocloft.