7.1 Figures
Figures are created using the figure environment.
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:
So far so good, but our picture needs to be centred. This can
be done using the \centering
declaration mentioned in
§2.12. Declarations:
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:
(As before we use ~ to make an unbreakable space.) This produces the following output in the text:
Important Note:
If you want to change the caption font, don't do, e.g.:
Recall\addtokomafont
from §5.3. Chapters, Sections, Subsections .... This can
also be used to change the fonts used by the caption.
Similarly for the caption label. For example:
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
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).