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.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}
This produces one figure on top of the other, instead of side-by-side, as illustrated in Figure 7.2 and Figure 7.3. This is because the blank line indicates a paragraph break, so each minipage is in a separate paragraph, so it's not possible for them to be on the same line.

If you want a bit of spacing in your code to make it more readable, use % to comment out the paragraph break. For example:

\end{minipage}%
%
\begin{minipage}{0.5\linewidth}

 
Figure 7.2: A Circle
Image of a circle
Figure 7.3: A Rectangle
Image of a rectangle


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