7.1.1 Side-By-Side Figures
Recall at the start of §7.1. Figures, I mentioned that the figure environment may contain one or more captions. In most cases, you'll just have a single caption per figure environment, but sometimes you may want to have two figures side-by-side, in which case you'll need two captions within the same figure environment in order to keep the figures together.
To do this, we can use the minipage environment, which was covered in §4.7. Boxes and Mini-Pages. Recall that the minipage environment creates a horizontal box, which means that two mini-pages can be placed side-by-side on the same line. All you need to do now, is place one image and caption in one mini-page, and the other image and caption in the neighbouring mini-page. (Do you remember what effect is obtained by placing a percent symbol at the end of a line?)
\begin
{figure}[htbp]
\begin
{minipage}{0.5\linewidth
}
\centering
\includegraphics
{circle}
\caption
{A Circle}
\label
{fig:circle}
\end
{minipage}%
\begin
{minipage}{0.5\linewidth
}
\centering
\includegraphics
{rectangle}
\caption
{A Rectangle}
\label
{fig:rectangle}
\end
{minipage}
\end
{figure}
Note that each
mini-page uses \centering
to centre its contents, and the
label is also placed in the same mini-page, after the
\caption
command. If the \label
was not in the same
scope as the \caption
, the
cross-reference would be incorrect.
A common mistake when trying to create side-by-side figures is to do:
\begin
{figure}[htbp]
\begin
{minipage}{0.5\linewidth
}
\centering
\includegraphics
{circle}
\caption
{A Circle}
\label
{fig:circle}
\end
{minipage}
\begin
{minipage}{0.5\linewidth
}
\centering
\includegraphics
{rectangle}
\caption
{A Rectangle}
\label
{fig:rectangle}
\end
{minipage}
\end
{figure}
If you want a bit of spacing in your code to make it more readable, use % to comment out the paragraph break. For example:
This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).