Subfigures (a), (b), (c) in LaTeX and how to reference them
Help centre › LaTeX › Figures · Packages: subcaption, graphicx
Load \usepackage{subcaption}, put each panel in a subfigure environment with its own \caption and \label inside one figure, and the panels are numbered (a), (b), (c). \ref{fig:panel} prints the figure and panel together (1a), and \subref{fig:panel} prints the letter alone (a).
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.32\textwidth}
\centering
\rule{\linewidth}{0.7\linewidth}% \includegraphics[width=\linewidth]{figures/raw}
\caption{Raw signal}\label{fig:raw}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.32\textwidth}
\centering
\rule{\linewidth}{0.7\linewidth}
\caption{Filtered}\label{fig:filtered}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.32\textwidth}
\centering
\rule{\linewidth}{0.7\linewidth}
\caption{Spectrum}\label{fig:spectrum}
\end{subfigure}
\caption{Processing steps: (\subref{fig:raw}) the raw signal,
(\subref{fig:filtered}) after filtering, (\subref{fig:spectrum}) its spectrum.}
\label{fig:steps}
\end{figure}
Figure~\ref{fig:steps} has three panels; Figure~\ref{fig:spectrum}
shows the spectrum.
\end{document}What \ref and \subref print
Each \label must come after the \caption it belongs to: the label takes the number of the last caption before it. Compile twice for references to settle.
\ref{fig:steps}(the label after the main caption) prints the figure number: 1.\ref{fig:spectrum}(a label after a subcaption) prints the figure number and the panel letter: 1c. WriteFigure~\ref{fig:spectrum}in the text.\subref{fig:spectrum}prints the panel letter alone: c. Written as(\subref{fig:spectrum}), as in the main caption of the example, it names a panel without repeating the figure number.
References written as 1(a) instead of 1a
Some journals want the panel in parentheses in references too. Make the counter itself carry the parentheses and tell the caption not to add a second pair:
\documentclass{article}
\usepackage{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}
\captionsetup[sub]{labelformat=simple}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.45\textwidth}\centering
\rule{\linewidth}{0.5\linewidth}\caption{Left}\label{fig:l}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.45\textwidth}\centering
\rule{\linewidth}{0.5\linewidth}\caption{Right}\label{fig:r}
\end{subfigure}
\caption{Two panels.}\label{fig:two}
\end{figure}
Figure~\ref{fig:r} is the right-hand panel.
\end{document}Other label styles
- Capital letters, (A), (B):
\renewcommand\thesubfigure{\Alph{subfigure}}. - Bold letters without parentheses:
\captionsetup[sub]{labelformat=simple,labelfont=bf}. - Letters only, with the description in the main caption: leave the subcaptions empty,
\caption{}. The letter is still printed and can still be referenced. - Subcaption font size and spacing:
\captionsetup[sub]{font=footnotesize,skip=2pt}.
Subtables
subcaption also provides subtable, which works the same way inside a table environment: (a), (b) subcaptions, references 1a, 1b. Put the subcaption above the tabular if your table captions go above.
\documentclass{article}
\usepackage{subcaption}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Results by group.}\label{tab:groups}
\begin{subtable}[t]{0.45\textwidth}
\centering
\caption{Group A}\label{tab:a}
\begin{tabular}{lr}
Trial & Score \\ \hline
1 & 0.81 \\
2 & 0.77 \\
\end{tabular}
\end{subtable}\hfill
\begin{subtable}[t]{0.45\textwidth}
\centering
\caption{Group B}\label{tab:b}
\begin{tabular}{lr}
Trial & Score \\ \hline
1 & 0.64 \\
2 & 0.70 \\
\end{tabular}
\end{subtable}
\end{table}
Table~\ref{tab:b} shows group B.
\end{document}Common mistakes
- Putting
\labelbefore\captionin a subfigure: the reference then shows the wrong number. - Using the old
subfigurepackage, orsubfigtogether withsubcaption; choose one, and prefersubcaption. - Writing the letters by hand in the picture and in a subcaption: the panel ends up labeled twice. If the letters are inside the image, use one caption and no subfigures.
- References printing ?? after the first compile: compile again.
In journal templates
- IEEEtran's template recommends the
subfigpackage (\usepackage[caption=false,font=footnotesize]{subfig}) and\subfloat[Caption]{…\label{…}}rather thansubcaption;\refand\subrefwork the same way there. - In two-column classes, a figure whose panels need the full page width is a
figure*, sized with\textwidth; it is placed at the top of a page.
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.
- Undefined control sequence.LaTeX met a command it does not know: usually a typo, or a command whose package is not loaded. The log's l. line ends with the culprit.
- 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.
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
- Two figures side by side in LaTeXPut two or three images side by side in LaTeX with subcaption (each with its own (a), (b) subcaption) or with minipage (each its own Figure number).
- 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