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
- Loading
subfigureorsubfigtogether withsubcaption: they define the same things differently.subfigureis obsolete; usesubcaption. - A blank line between the subfigures puts the second one under the first.
- Widths that add up to more than
\textwidth(two times0.5\textwidthplus the space between them) push the second picture to the next line or into the margin. \labelbefore\captioninside a subfigure refers to the figure number instead of the subfigure; put it after the caption.\includegraphics[width=\textwidth]inside a subfigure makes the picture as wide as the page; use\linewidth.
In journal templates
- In a two-column class,
\textwidthis the width of the whole page and\columnwidththe width of one column. For pictures side by side within one column, use fractions of\columnwidth; to span both columns, usefigure*with fractions of\textwidth. Afigure*goes at the top of a page (or on a page of floats), never where it is written. - IEEEtran's own template suggests
\usepackage[caption=false,font=footnotesize]{subfig}with\subfloat[Caption]{\includegraphics…}for subfigures, because the caption package (whichsubcaptionloads) changes IEEEtran's caption style. Follow the journal's instructions when they name a package.
Errors you may meet
- LaTeX Error: Environment <name> undefined\begin{…} names an environment no loaded package defines: load the package (amsmath for align), fix the spelling, or define it with \newtheorem.
- LaTeX Error: File `<name>' not foundLaTeX cannot find a file you asked for: an \input or image name that is misspelled or missing, or a package or class that is not installed.
- LaTeX Error: \caption outside float.\caption is used outside a figure or table environment. Wrap the content in figure or table, or use \captionof from the caption package.
- LaTeX Warning: Float too large for page by <n>pt on input line <n>.A figure or table is taller than the text area, so it overprints the footer or runs off the page. Scale it to fit, or split a long table.
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
- Subfigures (a), (b), (c) in LaTeX and how to reference themNumber panels (a), (b), (c) inside one figure with subcaption, refer to them as Figure 1a or just (a), and change the label style.
- Place a figure exactly here in LaTeX (stop it floating)Keep a LaTeX figure where you wrote it: [htbp] options, [H] from the float package, \FloatBarrier from placeins, and \clearpage to flush waiting figures.
- Wrap text around a figure in LaTeX (wrapfig)Put a figure beside the text with the text flowing around it, using the wrapfig package's wrapfigure environment, and avoid its usual problems.
The examples on this page were compiled with pdfLaTeX to check that they work as shown. LaTeX quick reference · LaTeX errors explained