About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Latest news 2019-11-04: The giveaway of two signed copies of “Quack, quack, quack. Give my hat back!” has closed and the winning entrants have been selected. Thank you to everyone who took part.


7.1 Figures

Figures are created using the figure environment.

\begin{figure}[<placement specifiers>]

This environment may contain one or more captions (specified, as described above, with the \caption command) but page breaks are not allowed in the contents of a figure environment. The optional argument <placement specifiers> is as described above.

Recall from §6. The graphicx Package that we can include an image in our document with the command \includegraphics defined in the graphicx package. We can put our shapes.pdf image into a figure as follows:

\begin{figure}[htbp]
  \includegraphics{shapes}
  \caption{Some Shapes}
\end{figure}

So far so good, but our picture needs to be centred. This can be done using the \centering declaration mentioned in §2.12. Declarations:

\begin{figure}[htbp]
  \centering
  \includegraphics{shapes}
  \caption{Some Shapes}
\end{figure}

The \caption command generates a number, just like \section, so we can cross-reference it with \ref and \label. First, let's label the figure:

\begin{figure}[htbp]
  \centering
  \includegraphics{shapes}
  \caption{Some Shapes}
  \label{fig:shapes}
\end{figure}

Now we can reference it:

Figure~\ref{fig:shapes} shows some shapes.

(As before we use ~ to make an unbreakable space.) This produces the following output in the text:

Figure 7.1 shows some shapes.

and produces Figure 7.1.

Figure 7.1: Some Shapes
 

Important Note:

If you want to change the caption font, don't do, e.g.:

\caption{\bfseries Some Shapes}
Recall \addtokomafont from §5.3. Chapters, Sections, Subsections .... This can also be used to change the fonts used by the caption.
\addtokomafont{caption}{\bfseries}
Similarly for the caption label. For example:

\addtokomafont{captionlabel}{\scshape}

List of Figures

Just as we were able to generate a table of contents using \tableofcontents, we can also generate a list of figures using the command

\listoffigures

This creates a file with the extension .lof (see §2.4. Auxiliary Files). As with \tableofcontents you will need to LaTeX your document twice to get the list of figures up-to-date, unless you're using latexmk (as described in §5.5. Cross-Referencing) in which case it will be done automatically.

Exercise 16: Creating Figures

If you did Exercise 15, you should have a document with an image in it. You now need to put this image into a figure environment. Remember to centre the image, and give the figure a caption. Next, try labelling the figure and referencing it in the text. You could also put in a list of figures after the table of contents. You can download or view an example.


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs