## 9 Graphics and Figures

### 9.1 The Figure Environment

Whenever you want to include graphics or pictures it's a very good idea to put them in a figure environment. LaTeX knows that the best places to put figures are at the top or bottom of a page, or perhaps on a separate page altogether. It also defines the command \caption{} which lets you add a caption for your figure. The basic syntax is as you'd expect by now:
 

\begin{figure}[h]
% ...
\caption{I'm sure you'll agree I have a good figure}
\end{figure}

 

The optional argument to the figure environment tells LaTeX where you'd like it to appear, if possible; the options are h meaning "here", t (at the top of a page), b (at the bottom of a page) and p (on a page without any text). This is only a suggestion to LaTeX, and it might ignore it if it doesn't think your instruction can be done neatly. If you want to encourage LaTeX to take your suggestion seriously you can put an exclamation mark before the location, e.g. \begin{figure}[!b].

If you want to refer to a figure in the text then you should add a \label as usual. The label should be placed inside the figure environment, after the caption.

### 9.2 Graphics Packages

Everyone likes to see images in any document. Whether it's a picture of the author, renderings of research or graphs, they can convey a lot of information in a small space. In order to include graphics in a LaTeX presentation you need to tell LaTeX how to handle them. The simplest way to do this is by using a graphics package, the most common of which is the graphicx package.

Once you've included the graphicx package in your document, you can include any graphics using the \includegraphics{} command, e.g.
 

\begin{figure}
\centerline{\includegraphics{dangermouse.jpg}}
\caption{Wherever there is danger he'll be there}
\label{DM}
\end{figure}

 
where I've used \centerline to make sure it appears in the centre.

You can have multiple graphics within a figure environment, and a single caption for each, e.g.
 

\begin{figure}
\centerline{\includegraphics{the_baron.jpg}}
\centerline{\includegraphics{nero.jpg}}
\centerline{\includegraphics{stiletto.jpg}}
\caption{Baron Silas Greenback, our hero's arch-nemesis, and his minions}
\label{DM}
\end{figure}

 

### 9.3 Image Formats

One of the drawbacks to putting images in LaTeX is that different forms of LaTeX accept different image formats. If you're making a PDF as we are today, then you can use JPG and PNG (or even PDF!). If you're making a postscript PS then the best image format to use is Encapsulated Postscript (EPS). Most journals prefer EPS figures because it is easier to print them in high quality.

### Important note: Draft Mode

If you've given the draft option in your \documentclass, then LaTeX will not display images! It will leave the correct amount of space for the picture, but it will just show an empty black box with the filename in it. If you want images to appear in your final output, then you must remove the draft option.

### Exercise 8

Use the graphicx package to include an image in your document. Make sure you include a caption and a label, and reference the figure in your text.

### Summary

• The figure environment is designed to contain pictures and figures, and lets you define a caption with \caption
• You can label captions just like any other LaTeX section
• The graphicx package has support for several image file formats