Two figures side by side in LaTeX

Help centre › LaTeX › Figures · Packages: subcaption, graphicx

Load \usepackage{subcaption} and put each image in a subfigure environment of width 0.48\textwidth inside one figure, separated by \hfill; each subfigure gets its own \caption (printed as (a), (b)) and the figure gets a main caption. If each image should be a numbered figure of its own (Figure 1, Figure 2), use two minipage environments instead, each with its own \caption.

A complete example

A whole document: paste it into an empty project and compile it.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}[htbp]
  \centering
  \begin{subfigure}[b]{0.48\textwidth}
    \centering
    % \includegraphics[width=\linewidth]{figures/before}
    \rule{\linewidth}{0.6\linewidth}
    \caption{Before treatment}
    \label{fig:before}
  \end{subfigure}%
  \hfill
  \begin{subfigure}[b]{0.48\textwidth}
    \centering
    % \includegraphics[width=\linewidth]{figures/after}
    \rule{\linewidth}{0.6\linewidth}
    \caption{After treatment}
    \label{fig:after}
  \end{subfigure}
  \caption{Samples before and after treatment.}
  \label{fig:samples}
\end{figure}

Figure~\ref{fig:samples} compares the samples; panel~\ref{fig:after}
shows the result.
\end{document}

How it works

A subfigure is a box of the width you give it (like a minipage), with its own caption numbered (a), (b), (c) inside the current figure. Two boxes of 0.48\textwidth leave a small gap; \hfill pushes them to the margins so the gap sits in the middle. Inside each box, size the picture to the box with \includegraphics[width=\linewidth]{…}: \linewidth is the width of the box, not of the page.

Do not leave a blank line between the subfigures: a blank line is a new paragraph, and the second image moves below the first. The % after \end{subfigure} stops the line end adding a space, which matters when the widths add up to almost the full line.

Three figures side by side

Use three boxes of 0.32\textwidth (three times 0.32 leaves room for the gaps) with \hfill between them.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}[htbp]
  \centering
  \begin{subfigure}[b]{0.32\textwidth}
    \centering
    \rule{\linewidth}{0.8\linewidth}
    \caption{Day 1}\label{fig:d1}
  \end{subfigure}\hfill
  \begin{subfigure}[b]{0.32\textwidth}
    \centering
    \rule{\linewidth}{0.8\linewidth}
    \caption{Day 7}\label{fig:d7}
  \end{subfigure}\hfill
  \begin{subfigure}[b]{0.32\textwidth}
    \centering
    \rule{\linewidth}{0.8\linewidth}
    \caption{Day 30}\label{fig:d30}
  \end{subfigure}
  \caption{Growth over thirty days.}\label{fig:growth}
\end{figure}
See Figure~\ref{fig:growth}, especially~\ref{fig:d30}.
\end{document}

Side by side without subcaptions: minipage

When the two pictures are separate figures (Figure 1 and Figure 2) that merely share a row, put two minipage environments in one figure and give each its own \caption. No extra package is needed for the layout.

When you want one caption for both and no (a)/(b) at all, simply put the two \includegraphics commands next to each other with \hfill between them, each with width=0.48\textwidth.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[htbp]
  \centering
  \begin{minipage}[b]{0.48\textwidth}
    \centering
    \rule{\linewidth}{0.6\linewidth}
    \caption{Field site in spring.}\label{fig:spring}
  \end{minipage}\hfill
  \begin{minipage}[b]{0.48\textwidth}
    \centering
    \rule{\linewidth}{0.6\linewidth}
    \caption{Field site in autumn.}\label{fig:autumn}
  \end{minipage}
\end{figure}
Figures~\ref{fig:spring} and~\ref{fig:autumn} show the site.
\end{document}

Two rows of figures (a 2 × 2 grid)

End the first row with a blank line (or \par), add a little space with \medskip or \vspace{1em}, then write the second row the same way. The subcaptions continue (c), (d).

\begin{figure}[htbp]
  \centering
  \begin{subfigure}[b]{0.48\textwidth}\centering
    \includegraphics[width=\linewidth]{figures/a}\caption{}\label{fig:a}
  \end{subfigure}\hfill
  \begin{subfigure}[b]{0.48\textwidth}\centering
    \includegraphics[width=\linewidth]{figures/b}\caption{}\label{fig:b}
  \end{subfigure}

  \medskip
  \begin{subfigure}[b]{0.48\textwidth}\centering
    \includegraphics[width=\linewidth]{figures/c}\caption{}\label{fig:c}
  \end{subfigure}\hfill
  \begin{subfigure}[b]{0.48\textwidth}\centering
    \includegraphics[width=\linewidth]{figures/d}\caption{}\label{fig:d}
  \end{subfigure}
  \caption{Four conditions: (a) control, (b) low dose, (c) medium dose, (d) high dose.}
\end{figure}

Lining up pictures of different heights

The optional argument of subfigure and minipage says which line of each box sits on the common baseline. With [b] the last lines (the subcaptions) line up, so captions stay level even when one picture is taller. With [t] the first lines line up; for a box that starts with a picture, that first line is the picture itself, whose baseline is its bottom edge, so the bottoms of the pictures line up instead.

To give pictures of different shapes the same height, size them by height: \includegraphics[height=4cm]{…}, and choose box widths to match.

Common mistakes

In journal templates

Errors you may meet

In Manulyx

Insert → Figure → Upload from computer… uploads an image into figures/ and inserts a figure for it; From project files uses an image already in the project. PDF, PNG and JPG work with pdfLaTeX.

Write in Manulyx for free · Journal templates

Related

The examples on this page were compiled with pdfLaTeX to check that they work as shown. LaTeX quick reference · LaTeX errors explained