Structuring your LaTeX document

This article explains how to add structure commands to your LaTeX document to split it into pieces and make it easy to navigate for your reader.

Section commands

You impart structure to your document with structure commands, e.g. \section, \subsection, etc. For example, to create simple sections and subsections, you can write

Structuring your LaTeX document
\section{First section}

Text that belongs to the first section

\subsection{First subsection}

Text that belongs to the first subsection

\section{Second section}

Text that begins to the second section

Numbering

There is no need to keep track of the section numbers in your document. The section and subsection commands will automatically assign numbers to the section titles. In the example above it would be translated by LaTeX to

  • 1. First Section
  • 1.1. First Subsection
  • 2. Second Section

The advantage of allowing LaTeX to take care of this for you is that when you insert a new section, the numbers will automatically be reassigned.

Nevertheless, you can suppress numbering with a *, for example

\section*{First section}

In this case the section will not be numbered.

Cross referencing

One of the main advantages of numbering is that it makes it very easy to other reference sections from within the text. You can insert a \label command at any point, then refer back to the section number containing that label using a \ref command. Similarly you can reference the page number with a \pageref commnad. For example

Cross referencing sections
\section{First section} \label{firstsection}
Something I want to refer to later.
\section{Second section}
The subject discussed in Section \ref{firstsection} on \pageref{firstsection} is very interesting.  Let me tell you why...

Although Texifier will take care of this detail for you, on other editors, or on the command line, you may need to typeset twice in order to resolve these references. On the first run TeX will calculate the positions of the labels, and store them in .aux files, on the second it will insert the actual references.

NB you can refer to figures in the same way. Be sure to insert the \label command inside the figure environment, then when you reference it, you will reference the enclosing figure rather than the enclosing section.

Table of contents or figures

It is often helpful to present a table of contents at the beginning of your document. To do this, simply insert the \tableofcontents command where you want the table to appear. As with section numbers, on editors other than Texifier you will need to typeset twice. On the first run Texifier will output a .toc file, then on the second run that will be inserted into your document.