Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 38 ยท Documents and Text Formatting

Sections, Title Pages and Table of Contents

Structure a LaTeX document with sections and subsections, build a title block and abstract, generate a table of contents, and control numbering, appendices and chapters.

Structure is where LaTeX repays the effort of learning it. You mark where a section begins, and LaTeX numbers it, formats the heading, adds it to the table of contents and keeps cross-references correct, even when you later move the section elsewhere. This lesson covers the sectioning commands, the title block, the abstract and the table of contents.

Sectioning commands

From the largest to the smallest unit:

Command Level Available in
\part{...} -1 all three standard classes
\chapter{...} 0 report, book
\section{...} 1 all
\subsection{...} 2 all
\subsubsection{...} 3 all
\paragraph{...} 4 all (a run-in heading, not numbered by default)
\subparagraph{...} 5 all
LATEX
\section{Methods}
We describe the procedure here.

\subsection{Participants}
Twenty students took part.

\subsection{Procedure}
Each student solved five problems.

\section{Results}
The results are shown below.

Numbering is automatic: Methods is 1, Participants is 1.1, Procedure is 1.2, Results is 2. Add a new section in the middle, and everything after it renumbers by itself.

A good rule of thumb: for a paper, use \section and \subsection; for a thesis, use \chapter, \section and \subsection. If you need \subsubsection regularly, restructure the text. Think of the outline as a tree:

flowchart TD
  D["Document"] --> S1["1 Methods"]
  D --> S2["2 Results"]
  S1 --> A["1.1 Participants"]
  S1 --> B["1.2 Procedure"]
  S2 --> C["2.1 Accuracy"]

LaTeX numbers the tree for you and knows each node's page.

Use the stand-in below to see this numbering behaviour. Type \section, \subsection and \subsubsection lines (and a starred one) and watch the generated contents list. It is a model of the idea, not the real compiler.

Automatic numbering and a table of contents (stand-in)

Notice that the starred \section*{Acknowledgements} is missing from the list. That leads to the next idea.

Starred variants and unnumbered sections

Adding * to a sectioning command gives an unnumbered heading that is not listed in the contents.

LATEX
\section*{Acknowledgements}
Thanks to everyone who helped.

To keep an unnumbered heading in the table of contents add it by hand:

LATEX
\section*{Acknowledgements}
\addcontentsline{toc}{section}{Acknowledgements}

You can also give a short title for the contents and page headers: \section[Short]{A very long section title that does not fit in the header}.

The title block

Declare the metadata in the preamble and print it with \maketitle in the body.

LATEX
\title{Sorting Algorithms in Practice}
\author{Ada Student\thanks{Example University.} \and Ben Learner}
\date{\today}

\begin{document}
\maketitle
  • \and separates several authors; \\ starts a new line inside one (for affiliations).
  • \thanks{...} adds a footnote marked with a symbol on the title.
  • \date{} with empty braces prints no date; leaving out \date prints today's date.
  • In article the title sits at the top of the first page. In report and book, or with the titlepage option, it gets a page of its own.

For a fancy cover, use the titlepage environment and arrange everything by hand, or load a thesis template.

LATEX
\begin{titlepage}
  \centering
  \vspace*{3cm}
  {\Huge\bfseries My Thesis\par}
  \vspace{1cm}
  {\Large Ada Student\par}
  \vfill
  {\large \today\par}
\end{titlepage}

The abstract

The abstract environment places a short summary under the title in article and report.

LATEX
\begin{abstract}
We compare four sorting algorithms on random and nearly sorted
inputs and report running times.
\end{abstract}

book has no abstract environment; add a starred chapter instead.

Table of contents and lists

One command, \tableofcontents, prints the contents. Put it after \maketitle and any abstract.

LATEX
\maketitle
\tableofcontents
\newpage

Two sister commands exist: \listoffigures and \listoftables, which collect captions (see figures and tables).

The two-run rule. LaTeX learns the section titles and page numbers during one run and writes them to a .toc file. The contents are printed on the next run. So a freshly added section appears in the contents only after compiling twice. Editors with latexmk do both runs for you, which is why a missing entry or "??" in the output usually just means "compile once more".

Depth is controlled with a counter: \setcounter{tocdepth}{2} lists down to subsections, and \setcounter{secnumdepth}{2} limits how deep headings are numbered.

Appendices and book parts

\appendix switches numbering to letters: sections become A, B and so on (chapters, in a report).

LATEX
\appendix
\section{Proofs}        % A Proofs
\section{Data tables}   % B Data tables

Books have three divisions that control page numbering and numbering of chapters:

LATEX
\frontmatter    % roman page numbers, unnumbered chapters
\tableofcontents
\mainmatter     % arabic numbers, numbered chapters
\chapter{Introduction}
\backmatter     % unnumbered chapters
\chapter{Bibliography}

Changing how headings look

Do not fight the heading style with manual \Large and \bfseries. Use the titlesec package, which restyles all headings at once:

LATEX
\usepackage{titlesec}
\titleformat{\section}{\Large\bfseries\sffamily}{\thesection}{1em}{}
\titlespacing*{\section}{0pt}{2ex}{1ex}

Or use the KOMA-Script classes (scrartcl, scrreprt, scrbook), which offer many ready-made options, for example \KOMAoptions{headings=small}.

Splitting a long document

For long documents, put each chapter in its own file and pull them together in main.tex:

LATEX
\input{chapters/intro}     % pastes the file's content here
\include{chapters/methods} % starts a new page; supports \includeonly

With \includeonly{chapters/methods} in the preamble, only that chapter is compiled, which speeds up work on large projects while page numbers and references stay correct from earlier runs.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which sectioning command is NOT available in the article class?

    \chapter exists in report and book only.
  2. 2. What does \section*{Notes} do?

    The star suppresses numbering and the contents entry.
  3. 3. You added a section but it is missing from the table of contents. What is the most likely reason?

    The contents are read from a file written in the previous run.
  4. 4. Which command prints the title block?

    \title and \author only store the data; \maketitle prints it.

Summary

  • \section, \subsection and friends create numbered, structured headings; \chapter needs report or book.
  • A star removes numbering and the contents entry.
  • \title, \author, \date and \maketitle build the title block; abstract adds a summary.
  • \tableofcontents needs two runs; \appendix, \frontmatter and \mainmatter change numbering schemes.
  • Split big documents with \input and \include.

Next: Page Layout and Margins with geometry