You're staring at a screen full of code, and all you want is to put two charts next to each other. It sounds simple. In Word, you’d just drag them. But this is LaTeX. You compile the document, and suddenly, one image is on page three, the other is floating in some digital void, and your captions are overlapping like a bad collage. Honestly, side by side pictures latex configurations are the bane of every grad student’s existence.
The struggle is real because LaTeX doesn't see "pictures." It sees boxes. If those boxes are even a fraction of a millimeter too wide for the text margin, the software just gives up and stacks them vertically. It’s frustrating. You’ve probably tried minipage or subfig, only to end up with a mess of "Undefined control sequence" errors. We need to talk about why this happens and the specific packages that actually work in 2026.
The subfigure vs. subcaption debate
Most old Stack Overflow threads tell you to use the subfigure package. Don’t do that. It’s been deprecated for ages. Seriously, it’s like trying to run modern software on Windows 95. If you use it, you’re going to run into compatibility issues with your document class eventually.
Then there’s subfig. It was the successor, and it’s okay, but it has some weird interactions with the caption package. If you want the most robust, modern way to handle side by side pictures latex layouts, you should be using subcaption. It’s cleaner. It handles hyperref better. It just feels more "native" to how modern LaTeX distributions like TeX Live handle floats.
When you use subcaption, you’re basically creating a parent figure environment and then nesting two subfigure environments inside it. Each sub-environment gets its own width. If you set each to $0.45\textwidth$, they’ll sit next to each other because $0.45 + 0.45$ is less than 1. Basic math, right? But if you forget to remove the empty line between the two \end{subfigure} and \begin{subfigure} tags, LaTeX interprets that whitespace as a paragraph break. Boom. Your images are stacked again.
The minipage workaround
Sometimes you don't want the fancy "Figure 1a" and "Figure 1b" labels. You just want two images sitting there, minding their own business. This is where minipage shines.
A minipage is essentially a "page within a page." You define its width, throw an image inside it, and move on. It’s the brute force method of the LaTeX world. It’s less "smart" than the subcaption package, which is exactly why it works when everything else is breaking. If you’re struggling with a complex template—like those picky IEEE or Elsevier ones—minipage is often the path of least resistance.
Just remember: $0.5\textwidth$ is a trap. If you have two minipages at exactly $0.5\textwidth$, they will almost always wrap to the next line because of the tiny amount of space between the boxes. Use $0.48$ or $0.49$. Give the document some room to breathe.
Fixing the alignment nightmare
Have you ever had two images side-by-side where one is a tall portrait and the other is a wide landscape? They look terrible. By default, LaTeX aligns them at the bottom (the baseline). This makes your document look like it was formatted by a toddler.
You can fix this by using alignment keys like [t] for top or [b] for bottom in your environment declaration. But here’s a pro tip: if you’re using the graphix package, you can use \raisebox to manually nudge one image up or down. It feels like a hack because it is one. But when you’re three hours away from a thesis deadline and your images won't line up, a hack is a lifesaver.
💡 You might also like: Images of the stars: Why your wallpaper looks nothing like the real universe
Another common headache is the "Too many unprocessed floats" error. This usually happens when you have a bunch of side-by-side images and LaTeX can't figure out where to put them without breaking the flow of text. Using the [H] placement specifier from the float package tells LaTeX, "Put this exactly here and stop trying to be smart about it." It’s controversial among LaTeX purists who think the software should handle placement, but let’s be real—sometimes the software is wrong.
Codes and real-world implementation
Let’s look at how you actually write this out. You need the subcaption package in your preamble. If you don't include \usepackage{subcaption}, none of this works.
Inside your document, the structure looks like this:
\begin{figure}[ht]\centering\begin{subfigure}[b]{0.45\textwidth}\includegraphics[width=\textwidth]{image1.jpg}\caption{The first image description.}\end{subfigure}\hfill\begin{subfigure}[b]{0.45\textwidth}\includegraphics[width=\textwidth]{image2.jpg}\caption{The second image description.}\end{subfigure}\caption{A global caption for both images.}\end{figure}
💡 You might also like: I Like You Facebook: Why This Weirdly Specific Phrase Still Breaks the Internet
Notice that \hfill in the middle? That’s the secret sauce. It pushes the two images to the far left and far right of the text margin, leaving a nice, clean gap in the center. Without it, they might just huddle together in the middle of the page, looking awkward.
When to use tabular for images
It sounds crazy, but sometimes the best way to handle side by side pictures latex is to use a table. Yeah, a tabular environment.
If you have a grid of four or six images, trying to manage them with subfigures is a recipe for a migraine. If you put them in a table, you get rigid control over the columns and rows. You can even use the array package to vertically center images within the table cells.
This isn't standard practice for a single pair of photos, but for a complex "results" section where you have twelve different heatmaps? Tables are much more stable. You just treat each \includegraphics command as if it were a piece of text inside a table cell. It works surprisingly well.
Common pitfalls to avoid
- Forgetting the percent sign: If you want to keep two pieces of code on separate lines for readability but don't want LaTeX to count the "enter" key as a space, put a
%at the end of the line. It "comments out" the line break. - The [width=] mistake: Always define your image width relative to the environment, not the whole page. If your subfigure is $0.5\textwidth$ wide, set your image to
width=\textwidth. This makes it fill 100% of that $0.5$ space. If you set the image towidth=0.5\textwidthinside a $0.5\textwidth$ subfigure, you end up with a tiny thumbnail. - Label placement: Always put your
\labelafter the\caption. If you put it before, your cross-references (like "See Figure 2") will point to the wrong section or just show up as a double question mark.
Beyond the basics: adjustbox
If you’re really struggling with sizing, check out the adjustbox package. It’s like a Swiss Army knife for images. It lets you trim, rotate, and scale images on the fly without having to go back into Photoshop or GIMP.
📖 Related: Project Orion: The True Story of the Atomic Spaceship and Why We Never Built It
Specifically, the valign=m option in adjustbox is a godsend for side-by-side images of different heights. It forces them to align along their middle axis. It makes the whole layout look professional with almost zero effort.
Essential next steps
Start by cleaning up your preamble. Get rid of subfigure and subfig if they’re lingering in your code from old templates. Replace them with subcaption.
Next, try the \hfill trick. It’s the easiest way to fix spacing issues without messing with manual centimeters or inches. If your images are still jumping to the next page, check your total widths. If $SubfigureA + SubfigureB > 1.0$, it’s never going to work. Keep your combined widths around $0.9$ to account for margins and hidden spaces.
Finally, compile frequently. Don’t write 20 pages of text and then try to add 10 sets of side-by-side images. Do them one by one. LaTeX is powerful, but it's also sensitive. One missing bracket in a subfigure caption can break your entire PDF, and finding that needle in the haystack is a nightmare you don't want.
Check your log files for "Overfull \hbox" warnings. Those are the early warning signs that your side-by-side images are wider than your margins. If you see those, dial back your \textwidth percentages by a percent or two. It’s usually enough to coax the compiler into doing what you want.