You've been there. You are staring at a document that looks perfect, except for two stubborn images stacked vertically, leaving a massive, ugly white gap on the right side of the page. It's frustrating. You just want latex 2 figures side by side to look professional, but instead, they’re drifting apart like awkward teenagers at a dance.
Honestly, LaTeX is brilliant until it isn't.
💡 You might also like: Car Rear View Mirror Safety: Why Most Drivers Are Still Blind to the Basics
The struggle usually comes down to the fact that LaTeX treats images like giant letters. If they are too wide to sit next to each other, it just "typesets" the second one on the next line. Fixing this isn't just about shrinking the images; it’s about telling LaTeX exactly how much horizontal real estate each one is allowed to occupy.
The Subfig and Subcaption Dilemma
For years, everyone used the subfig package. It was the standard. Then things changed. Most modern journals and templates, especially those using the caption package, now prefer subcaption. If you mix them up, you’ll get errors that make no sense.
Basically, if you want your latex 2 figures side by side to have individual labels like (a) and (b) while sharing a main caption, subcaption is your best friend.
Here is the secret: the minipage environment or the subfigure environment. Both work by carving the line width into pieces. If you give each figure $0.45\textwidth$, you leave a $0.1\textwidth$ gap for "breathing room." That’s the trick. If you give them both $0.5\textwidth$, they might still stack because of a tiny bit of hidden whitespace.
Why Your Images Keep Jumping to the Next Line
Ever noticed how a single space in your code can ruin a layout? In LaTeX, a carriage return between two minipage blocks is treated as a space. That tiny space has a width. If your two images plus that space exceed the total page width, boom—the second image drops down.
You have to use a percent sign % right after the first \end{minipage} or \end{subfigure}. This "comments out" the line break, essentially telling LaTeX, "Don't put a space here; keep the next block glued to this one." It’s a tiny detail, but it’s usually the reason why people can't get their figures to align.
Let's Look at a Real Example
Imagine you're writing a paper on fluid dynamics. You have a plot of velocity and a plot of pressure. You need them level.
\usepackage{subcaption}
\usepackage{graphicx}
\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.48\textwidth}
\centering
\includegraphics[width=\textwidth]{velocity_plot.png}
\caption{Velocity profile}
\label{fig:vel}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.48\textwidth}
\centering
\includegraphics[width=\textwidth]{pressure_plot.png}
\caption{Pressure distribution}
\label{fig:pres}
\end{subfigure}
\caption{Comparing fluid properties at the nozzle exit.}
\label{fig:comparison}
\end{figure}
The \hfill command is doing a lot of heavy lifting there. It pushes the two subfigures to the absolute edges of the margins, creating a perfectly balanced gap in the middle. If you want them closer together, you’d replace \hfill with a specific distance like \hspace{1cm}.
The Old School Minipage Method
Sometimes you don't want (a) and (b) labels. Maybe you just want two independent figures that happen to sit next to each other. In that case, you don't even need the subcaption package. You just wrap two separate figure environments? No, that won't work. You wrap two minipage environments inside one single figure environment.
It’s a bit of a hack, but it’s incredibly stable.
The downside is that they will share one figure number unless you do some clever labeling. If you need them to be "Figure 1" and "Figure 2" while sitting side by side, you're looking at a much more complex setup involving the captionof command from the caption package. Honestly, it's usually better to just let them be subfigures. It's cleaner for the reader.
Common Pitfalls With Vertical Alignment
Not all images are born equal. Some are tall and skinny; others are short and wide. When you put latex 2 figures side by side, LaTeX defaults to aligning their "baselines." If one caption is three lines long and the other is one line, the actual images will look unaligned and messy.
Use the [b] (bottom) or [t] (top) alignment specifiers.
Usually, [b] looks best because it keeps the images sitting on the same horizontal "floor," even if their heights differ. If you use [t], the tops will align, which is great for flowcharts or diagrams but can look weird for photos.
What About Floating?
We have all been there. You place your figure code right after a paragraph, and LaTeX decides to banish it to page 47.
The [htbp] tag is your suggestion to LaTeX: "Put it here, at the top of the page, at the bottom, or on a page of its own." If you are absolutely desperate and want to force it, use the float package and the capital [H]. Just be warned: [H] is a hammer. It can create massive white spaces at the bottom of pages because LaTeX will literally stop everything to place that figure right there.
Why Placement Matters for SEO and Readers
When you're designing these layouts for a digital PDF or a web-rendered version of a paper, readability is king. Two tiny, cramped figures are worse than two large, stacked ones. If your images have small text (like axis labels on a graph), $0.48\textwidth$ might be too small to read.
In those cases, you might consider rotating the images or just biting the bullet and stacking them. Accessibility experts, like those at the W3C, often point out that side-by-side layouts can be tricky for screen readers if the reading order isn't clearly defined in the underlying metadata. While LaTeX to PDF is a bit different, the logic holds: keep it simple.
Pro Tips for Clean Code
- Always use \textwidth: Avoid using absolute units like
cmorinchesfor the subfigure width. If you change your page margins later,\textwidthwill automatically scale your images.cmwill not. - The "Draft" Option: If you have 50 high-res images and your document takes three minutes to compile, add
draftto your\documentclassoptions. It replaces images with boxes, saving you hours of waiting while you tweak the layout. - Clear Graphics Path: Use
\graphicspath{{images/}}so your code isn't cluttered with long file paths.
Dealing With "Too Many Unprocessed Floats"
If you have a lot of side-by-side figures, you might hit the dreaded "Too many unprocessed floats" error. This is LaTeX's way of saying it has too many images in its "waiting room" and doesn't know where to put them.
The \clearpage command is the "flush" button. It forces LaTeX to dump all the figures it's holding onto the current page before starting the next section. Alternatively, the extraplaceins package can help manage this if you're working on a massive thesis or a book.
📖 Related: iPhone Case for iPhone: Why Most People Are Still Buying the Wrong One
Practical Next Steps
Getting your latex 2 figures side by side to look right is mostly about managing your widths and using the right packages. Don't fight the system; work with the box model.
- Add
\usepackage{subcaption}to your preamble. - Open a
figureenvironment and set\centering. - Create two
subfigureblocks, each with a width of0.45\textwidth. - Use
\hfillbetween them to maximize the horizontal space. - Make sure your image widths are set to
width=\textwidthinside the subfigure environment so they fill the allocated $0.45$ space. - Double-check for any accidental carriage returns between your subfigure blocks.
If the images still won't sit side by side, check your margins. If you're using a two-column layout (like in IEEE papers), you should use the figure* environment to make the images span across both columns, though the internal logic for the subfigures remains the same. Professional typesetting is less about "fixing" and more about "defining" constraints. Once you give LaTeX the right constraints, it does the heavy lifting for you.