LATEX provides seven levels of division or sectioning
for you to use in structuring your text. They are all
optional: it is perfectly possible to write a document
consisting solely of paragraphs of unstructured text. But even
novels are normally divided into chapters, although short
stories are often made up just of paragraphs.
Table 2.1: LATEX’s sectioning commands
Depth | Division | Command | Notes |
–1 | Part | \part | Not in letters |
0 | Chapter | \chapter | Books and reports only |
1 | Section | \section | Not in letters |
2 | Subsection | \subsection | Not in letters |
3 | Subsubsection | \subsubsection | Not in letters |
4 | Titled paragraph | \paragraph | Not in letters |
5 | Titled subparagraph | \subparagraph | Not in letters |
Chapters are only available in the book and report document classes, because
chapters don’t have any meaning in articles or letters. For
the same reason, Parts are also undefined in letters.
In each case the title of the part, chapter, section, etc
goes in curly braces after the command. LATEX automatically
calculates the correct numbering and prints the title in bold
with appropriate spacing above and below (parts and chapters
always start a new page). You can turn section numbering off
at a specific depth: details are in § 2.6.1 below.
...
\chapter{Organisational changes 2020}
...
\section{New recruitment policies}
...
\subsection{Effect on staff turnover}
...
\chapter{Business plan 2020--2030}
...
There are packages to let you control the typeface, style,
spacing, and appearance of section headings: it’s much easier
to use them than to try and reprogram the headings manually.
Some of the most popular are section,
titlesec, and sectsty;
see https://ctan.org/recommendations/section for
others.
Headings also get put automatically
into the Table of Contents, if you specify one
(\tableofcontents is optional). But if you
make manual styling changes to your heading, for example a
very long title, or some special line-breaks or unusual
font-play, this would appear in the Table of Contents as well,
which you almost certainly don’t want.
LATEX allows you to give an optional extra version of the
heading text which only gets used in the
Table of Contents (and any running heads, if they are in
effect: see § 6.1.2 below). This alternative
heading goes in [square brackets] before the curly braces:
\section[Effect on staff turnover]{An analysis of the
effects of the revised corporate recruitment policies
on staff turnover at divisional headquarters}
Exercise 2.6 — Start your document text
Add a \chapter command after your
Abstract or Summary, giving the title of your first
chapter.
If you’re planning ahead, add a few more
\chapter commands for subsequent
chapters. Leave a few blank lines between them to make
it easier to add paragraphs of text later.
Typeset the document.
2.6.1 Section numbering
All document divisions get numbered automatically.
Parts get Roman numerals (Part I, Part II, etc);
chapters and sections get decimal numbering like this
document, and Appendixes (which are just a special case of
chapters, and share the same structure) are lettered (A, B,
C, etc). You can easily change this default if you want some
special scheme.
You can change the depth to which section numbering
occurs, so you can turn it off selectively. In this document
the depth is set
to 3,
using the depth column in Table 2.1 above. If you only
want parts, chapters, and sections numbered, not
subsections, subsubsections, or lower levels, you can change
the value of the
secnumdepth counter using the the
\setcounter command, giving the depth
value from Table 2.1 above:
\setcounter{secnumdepth}{1}
Notice that the \setcounter command,
like \renewcommand which we saw earlier,
has two arguments: the name of the counter you want to set,
and the number you want to set it to.
A related counter is tocdepth, which specifies what
depth to take the Table of Contents to. It can be reset
independently, in exactly the same way as secnumdepth. The setting for this
document is 2, but you can
set it to any appropriate level number from Table 2.1 above:
\setcounter{tocdepth}{3}
To get a one-time (special case)
unnumbered section heading which does
not go into the Table of Contents,
follow the command name with an asterisk before the opening
curly brace:
\subsection*{Shopping List}
All the divisional commands from
\part* to \subparagraph*
have this ‘starred’ version which can
be used in isolated circumstances for an unnumbered heading
when the setting of
secnumdepth would
normally mean it would be numbered.
2.6.2 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.
Table of Contents automation
Your editor should automatically run LATEX twice
when needed, if you are using a
Build,
Compile,
Typeset, or
Make button or menu entry. It is
also done automatically by processing tools like
latexmk, but if you are
processing LATEX manually by typing the commands in a
terminal window, you will need to run LATEX twice
yourself.
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 (this section) 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 2.7 — Using a Table of Contents
Add the \tableofcontents command
to your document, before or after the Abstract, as you
prefer.
Typeset the document.
Check that the Table of Contents is now
showing. If not, typeset the document again.
If what you expect doesn’t appear, you should always
check the log file or error display: you might have made a
typing mistake in a command.
A \tableofcontents command normally
shows only numbered section headings, and only down to the
level defined by the
tocdepth counter (see § 2.6.1 above), 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:
\subsection*{Preface}
\addcontentsline{toc}{subsection}{Preface}
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 at some
special place, you could say
\addtocontents{toc}{\par\hrule\vspace{6pt}}
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 automatically; perhaps the best-known is
tocloft.