Previously we examined the global structure of a LaTeX file. In this lesson we will learn how to add even more structure to our texts by means of chapters, paragraphs, a table of contents, etc. We will also discuss tables and figures.

Document classes

Recall that a document class is a collection of settings fitting a type of document. The document class can be adjusted with using

\documentclass[options]{class}

where options is a list of options seperated by commas. For example, the command

\documentclass[11pt,twoside,a4paper]{article}

starts an article with text size 11pt and the layout for twosided printing on A4 paper.

There exist many document classes for LaTeX. Standard document classes are classes which are always available. The most important standard document classes are

class document type
article articles in scientific journals, short reports, notes
report longer reports with chapters, small books, theses
book books
beamer presentations

Commonly used options for these document classes are

option description
10pt, 11pt, 12pt adjusts the size of the text, default is 10pt
a4paper, letterpaper adjusts the paper size, default depends on your distribution
twoside, oneside determines whether the document is formatted for one-sided or two-sided printing

The document environment

Last week we saw how to typeset the topmatter using \author, \title, \date and \maketitle. We will now discuss more commands to structure text in an article, report or book.

The following commands are used for chapters, sections and paragraphs:

table(table).

command level                              
\part -1 (optional)
\chapter 0 (only in book and report)
\section 1  
\subsection 2  
\subsubsection 3  
\paragraph 4  
\subparagraph 5  

The highest level in an article is \section and the highest level in book and report is \chapter.

The command \tableofcontents creates a table of contents. If you load the package hyperref all its elements will be clickable.

Often, articles start with a summary. This can be typeset with an abstract environment.

Definitions and theorems

For definitions, theorems, lemmas, etc. we use the package amsthm. This package introduces three layouts: plain, definition and remark. The preamble could for example contain

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}

\theoremstyle{definition}
\newtheorem{definition}{Definition}

\theoremstyle{remark}
\newtheorem{remark}{Remark}
\newtheorem{example}{Example}

The command \newtheorem{name}{Header} creates a new environment with name name and header Header. The command \theoremstyle determines the layout.

The code above creates four environments: theorem, definition, remark and example. The three different types of theorems all get a different layout.

Theorem 1. Lorem ipsum.

Definition 1. Lorem ipsum.

Remark 1. Lorem ipsum.

Example 1. Lorem ipsum.

\begin{theorem}
Lorem ipsum.
\end{theorem}

\begin{definition}
Lorem ipsum.
\end{definition}

\begin{remark}
Lorem ipsum.
\end{remark}

\begin{example}
Lorem ipsum.
\end{example}

It can be seen that the environments are numbered automatically. By default, every environment gets its own ‘counter’. It is customary (and clear) to use the same counter for all environments. You can attach a counter to an amsthm environment by adding the name of the counter as an optional argument in \newtheorem. In the next example, every environment uses the counter of theorem.

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}

\theoremstyle{definition}
\newtheorem{Definition}[theorem]{Definitie}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{example}[theorem]{Example}

Proofs can be set in amsthm with the proof environment.

Figures and tables

Tabels can be created with the tabular environment.

Example of a table.

\begin{tabular}{llr}
\hline
object & height (cm) & weight (kg) \\
\hline
monkey & 50 & 20 & 3\\
nut & 1 & 20 0.10 \\
\hline
\end{tabular}

With the options l, c and r you set the number of columns and the alignment of text in a columm. You can make a horizontal line with \hline.

To add a number and caption to the table we use the table environment.

\begin{table}
\centering
\begin{tabular}{llr}
\hline
object & height (cm) &w eight (kg) \\
\hline
monkey & 50 & 20 & 3\\
nut & 1 & 20 0.10 \\
\hline
\end{tabular}
\caption{Some properties of monkeys and nuts}
\label{tab:monkeynut}
\end{table}

We put the tabular environment inside a table environment. The table environment creates a so-called float. This is a box for which LaTeX determines the location on the page. LaTeX tries to put tables and figures together such that the text is interrupted as little as possible. We used \label to create a label in order to refer to this table later on. If you want to create more professional tables you could take a look at the booktabs package. More options can be found at Wikibooks/Tables.

Figures can be inserted with the package graphicx and the command \includegraphics. Supported extensions are pdf, png and jpg.

\includegraphics{figurename}

The argument of includegraphics is the name of the figure without its extension. LaTeX will search in the folder containing the .tex file for a file with the given name and a supported extension. Therefore you should watch out for files with the same name but a different extension: LaTeX might choose the wrong file.

There also exists a float for figures, the figure environment:

\begin{figure}
\includegraphics{figuur}
\caption{Een figuur.}
\label{fig:voorbeeld}
\end{figure}

See Wikibooks/Importing Graphics for more options.

References

Last week we saw how to refer to formulas using \label and \eqref. In the same way we can refer to chapters, section, theorems, definitions, etc. For example we can refer to a \section:

\section{Derivative}
\label{sec:derivative}

\section{Primitive}
In section \ref{sec:derivative} we saw the definition of a derivative.

For \part, \chapter, etc. referencing works in the same way. For theorem environments you should put the label directly after \begin{theorem}. For floats like figure and table the label should be put after the caption.

You have to compile twice for the right reference to appear. The first time you typeset your text, question marks will appear.

The advantage of referencing this way over referencing by hand is that the number will always be correct, even after you insert more text or change the order of the figures.

Bibliography

A bibliography can be created in the following way:

\documentclass{article}

\begin{document}
We refer to Lamport \cite{lamport94}.

\begin{thebibliography}{x}
\bibitem{lamport94}
Leslie Lamport,
\emph{\LaTeX: A Document Preparation System}.
Addison Wesley, Massachusetts,
2nd Edition,
1994.
\end{thebibliography}

\end{document}

The bibliography is put in the thebibliography environment. The argument x indicates that the counter for citations will consist of one character. You can use xx for up to 99 citations. A citation is inside a \bibitem. The first group after that is the label. We refer to the source with \cite plus the label of the citations.

We don’t recommand this way of citing for texts with many citations. You could use bibtex, see Wikibooks/Bibliography Management. However, some publishers (e.g. Nature) don’t accept bibtex files.

Exercise

Make a very short LaTeX article with the following properties:

  • it’s an article
  • you are the author and the title is “A short proof of the coloring theorem”
  • there is a picture in the article
  • it contains four numbered sections: Introduction, Definitions, Lemmas, Proof
  • it has a table of contents (let LaTeX create this for you)
  • all elements in the table of contents are clickable
  • it has a small bibliography and there is at least one citation
  • the lemma section is labeled with \label{lemmas} and in the proof section there is a reference to this label.

Remember

  • How to create chapters, sections, etc.?
  • How to create definitions and theorems?
  • How to insert figures and tables?
  • How to cite?
  • How to create a bibliography?