Getting Started
Text Formatting
Mathematical Expressions
Document Structure
Page Layout
Errors & Troubleshooting
Subfigures in LaTeX: Side-by-Side Figures with subcaption
Use the subcaption package. Two other packages have claimed this job over the years — subfigure is dead and subfig is frozen — and both still haunt old templates, but subcaption is the one that is maintained and the one every answer below assumes.
Two figures side by side
Each subfigure is a box of the given width; inside it, width=\linewidth makes the image fill that box. The \hfill pushes the two boxes to the margins and absorbs the leftover space between them.
Why 0.48, not 0.5
Two boxes of 0.5\textwidth plus the space between them add up to more than \textwidth, so the second box wraps to the next line and your figures stack vertically. That small deficit — 0.48 + 0.48 leaves 4% for \hfill to distribute — is what keeps them on one line. Same logic for three across: 0.31\textwidth each.
The other stacking culprit: a blank line between the subfigure environments. Blank line = paragraph break = new line. If you want the source spaced out visually, end the spacer line with %.
Referencing: \ref vs \subref
With labels on both the subfigures and the enclosing figure, you get three distinct behaviors:
\ref{fig:comparison}→ "1" — the whole figure\ref{fig:baseline}→ "1a" — figure number plus subfigure letter, ready for running text\subref{fig:baseline}→ "(a)" — the letter alone, for use inside the main caption or right after you have already written the figure number
A caption like "Baseline \subref vs ours \subref" reads naturally; \ref there would print a redundant "1a" inside Figure 1's own caption.
A 2×2 grid
Here the paragraph-break behavior works for you: a blank line between the pairs starts the second row.
Unequal heights: top-align with [t]
When the images have different heights, the default alignment centers each subfigure on the text baseline and the captions land at different depths. Pass [t] to each subfigure to align their tops:
If instead you want the captions on one line regardless of image height, keep [t] and give both images the same height=, or accept the honest fix: crop the images to matching aspect ratios before they reach LaTeX.
The subcaption-vs-subfig clash
Some journal classes (a number of IEEE and ACM-derived templates) load subfig internally. Load subcaption on top and you get Package caption Error: The caption package is not compatible or a complaint about option clashes. Your options, in order of preference:
- Use the class's own
\subfloatsyntax and skip subcaption entirely — least friction with the publisher - Load
\usepackage[compatibility=false]{caption}before subcaption to force the issue — works, but you own any caption-style drift from the template
Caption labels: (a) vs a)
\captionsetup from the same package family controls how the subfigure labels print:
Check your target journal before styling anything — most classes already set this, and overriding it is a common desk-edit complaint.
Frequently asked questions
How do I put two figures side by side in LaTeX?
Load the subcaption package and put two subfigure environments inside one figure, each 0.48\textwidth wide, separated by \hfill. Each subfigure gets its own \caption and \label, and the figure gets one main \caption below them.
Should I use subfigure, subfig or subcaption?
subcaption. The old subfigure package is obsolete and subfig is frozen; subcaption is maintained, plays well with the caption package, and is what current templates expect. Only touch subfig if a journal class forces it on you.
Why do my side-by-side figures stack on top of each other?
Almost always a blank line between the two subfigure environments — a blank line is a paragraph break, which forces a new line. Keep the subfigures on adjacent lines with at most a comment (%) between them, or put \hfill on its own line ending in %.
How do I reference one subfigure, like “Figure 1a”?
Give the subfigure its own \label inside its \caption, then \ref{fig:a} prints 1a. \subref{fig:a} prints just the (a) part, which is what you want in the main caption or in text that already names the figure number.
Subfigures in LaTeX: Side-by-Side Figures with subcaption
Use the subcaption package. Two other packages have claimed this job over the years — subfigure is dead and subfig is frozen — and both still haunt old templates, but subcaption is the one that is maintained and the one every answer below assumes.
Two figures side by side
Each subfigure is a box of the given width; inside it, width=\linewidth makes the image fill that box. The \hfill pushes the two boxes to the margins and absorbs the leftover space between them.
Why 0.48, not 0.5
Two boxes of 0.5\textwidth plus the space between them add up to more than \textwidth, so the second box wraps to the next line and your figures stack vertically. That small deficit — 0.48 + 0.48 leaves 4% for \hfill to distribute — is what keeps them on one line. Same logic for three across: 0.31\textwidth each.
The other stacking culprit: a blank line between the subfigure environments. Blank line = paragraph break = new line. If you want the source spaced out visually, end the spacer line with %.
Referencing: \ref vs \subref
With labels on both the subfigures and the enclosing figure, you get three distinct behaviors:
\ref{fig:comparison}→ "1" — the whole figure\ref{fig:baseline}→ "1a" — figure number plus subfigure letter, ready for running text\subref{fig:baseline}→ "(a)" — the letter alone, for use inside the main caption or right after you have already written the figure number
A caption like "Baseline \subref vs ours \subref" reads naturally; \ref there would print a redundant "1a" inside Figure 1's own caption.
A 2×2 grid
Here the paragraph-break behavior works for you: a blank line between the pairs starts the second row.
Unequal heights: top-align with [t]
When the images have different heights, the default alignment centers each subfigure on the text baseline and the captions land at different depths. Pass [t] to each subfigure to align their tops:
If instead you want the captions on one line regardless of image height, keep [t] and give both images the same height=, or accept the honest fix: crop the images to matching aspect ratios before they reach LaTeX.
The subcaption-vs-subfig clash
Some journal classes (a number of IEEE and ACM-derived templates) load subfig internally. Load subcaption on top and you get Package caption Error: The caption package is not compatible or a complaint about option clashes. Your options, in order of preference:
- Use the class's own
\subfloatsyntax and skip subcaption entirely — least friction with the publisher - Load
\usepackage[compatibility=false]{caption}before subcaption to force the issue — works, but you own any caption-style drift from the template
Caption labels: (a) vs a)
\captionsetup from the same package family controls how the subfigure labels print:
Check your target journal before styling anything — most classes already set this, and overriding it is a common desk-edit complaint.
Frequently asked questions
How do I put two figures side by side in LaTeX?
Load the subcaption package and put two subfigure environments inside one figure, each 0.48\textwidth wide, separated by \hfill. Each subfigure gets its own \caption and \label, and the figure gets one main \caption below them.
Should I use subfigure, subfig or subcaption?
subcaption. The old subfigure package is obsolete and subfig is frozen; subcaption is maintained, plays well with the caption package, and is what current templates expect. Only touch subfig if a journal class forces it on you.
Why do my side-by-side figures stack on top of each other?
Almost always a blank line between the two subfigure environments — a blank line is a paragraph break, which forces a new line. Keep the subfigures on adjacent lines with at most a comment (%) between them, or put \hfill on its own line ending in %.
How do I reference one subfigure, like “Figure 1a”?
Give the subfigure its own \label inside its \caption, then \ref{fig:a} prints 1a. \subref{fig:a} prints just the (a) part, which is what you want in the main caption or in text that already names the figure number.
Getting Started
Text Formatting
Mathematical Expressions
Document Structure
Page Layout
Errors & Troubleshooting
