How to Place Figures Side by Side in LaTeX
The fix
Use the subcaption package (the modern replacement for the old subfigure and subfig packages). Inside one figure environment, add several subfigure environments set to a fraction of \textwidth, each with its own \includegraphics, \caption, and \label — they are lettered (a), (b), (c) automatically.
Example
\usepackage{graphicx}
\usepackage{subcaption}
\begin{figure}
\begin{subfigure}{0.48\textwidth}
\includegraphics[width=\linewidth]{a.png}
\caption{First}\label{fig:a}
\end{subfigure}\hfill
\begin{subfigure}{0.48\textwidth}
\includegraphics[width=\linewidth]{b.png}
\caption{Second}\label{fig:b}
\end{subfigure}
\end{figure}Frequently asked questions
subcaption, subfig, or subfigure?
Use subcaption — it is current and integrates with the caption package. The older subfig and subfigure packages still work but can clash; do not load more than one.
How do I reference a subfigure?
Give each subfigure a \label and reference it with \ref{fig:a}, which prints "1a". With cleveref, \cref{fig:a} prints "Figure 1a".
Try the fix in LetX
Open the editor, paste your code, and compile in 1 second to see the error clear — free, in your browser.
Open LetX Free