How To Insert Images Side By Side In Latex

9 min read

How to Insert Images Side by Side in LaTeX

Inserting images side by side in LaTeX is one of the most common challenges for students, researchers, and academics drafting technical documents. Whether you are creating a scientific paper, a thesis, or a lab report, the ability to present comparative visuals or a series of related figures in a single row is essential for a professional layout. While LaTeX is renowned for its powerful typesetting, its approach to image placement—known as floating—can be intimidating for beginners. This guide will walk you through the most effective methods to align images horizontally, ensuring your document looks polished and meets academic standards.

Introduction to Image Handling in LaTeX

Before diving into the side-by-side configuration, it actually matters more than it seems. Instead, it uses a system of floats. A float is a container (like the figure environment) that tells LaTeX, "This content is important, but place it where it fits best on the page to avoid awkward white space Not complicated — just consistent..

To handle images, you must first include the graphicx package in your document preamble. This package provides the necessary commands to scale, rotate, and position your graphics.

\usepackage{graphicx}

When placing images side by side, the primary goal is to manage the total width of the row. Since a standard page has a finite width, you must make sure the combined width of your images (plus any padding between them) does not exceed \textwidth. If the total exceeds 100%, LaTeX will automatically push the second image to a new line.

Method 1: Using the Minipage Environment

The minipage environment is the most versatile and widely used method for placing images side by side. A minipage essentially creates a "page within a page," allowing you to treat a portion of the line as a separate block of text or imagery.

Step-by-Step Implementation

To place two images side by side, you create two minipage environments inside a single figure environment.

  1. Start the Figure Environment: This ensures both images are grouped together and share a single main caption.
  2. Define the First Minipage: Set the width (e.g., 0.45\textwidth).
  3. Insert the Image: Use \includegraphics and set the width to \linewidth so the image fills the minipage.
  4. Add a Gap: Use \hfill to push the two minipages to the opposite edges of the page, creating a clean center gap.
  5. Define the Second Minipage: Repeat the process for the second image.

Example Code:

\begin{figure}[htbp]
  \centering
  \begin{minipage}{0.45\textwidth}
    \centering
    \includegraphics[width=\linewidth]{image1.jpg}
    \caption{Description of the first image.}
    \label{fig:image1}
  \end{minipage}
  \hfill
  \begin{minipage}{0.45\textwidth}
    \centering
    \includegraphics[width=\linewidth]{image2.jpg}
    \caption{Description of the second image.}
    \label{fig:image2}
  \end{minipage}
  \caption{Overall caption for both images.}
  \label{fig:combined_images}
\end{figure}

Why Use Minipages?

The beauty of this method is that each minipage can have its own individual \caption and \label. This allows you to refer to "Figure 1a" and "Figure 1b" independently while still keeping them visually paired.

Method 2: Using the Subcaption Package (The Modern Standard)

For those writing formal academic papers, the subcaption package is the gold standard. In real terms, g. It allows you to create subfigures, which are logically linked to a parent figure. So this is the preferred method for journals because it automatically handles the numbering (e. , Figure 1a, 1b).

Setup and Execution

First, add the package to your preamble:

\usepackage{subcaption}

Then, use the subfigure environment. This works similarly to the minipage but is specifically optimized for graphics.

Example Code:

\begin{figure}[htbp]
     \centering
     \begin{subfigure}[b]{0.45\textwidth}
         \centering
         \includegraphics[width=\linewidth]{image1.jpg}
         \caption{First subfigure}
         \label{fig:sub1}
     \end{subfigure}
     \hfill
     \begin{subfigure}[b]{0.45\textwidth}
         \centering
         \includegraphics[width=\linewidth]{image2.jpg}
         \caption{Second subfigure}
         \label{fig:sub2}
     \end{subfigure}
     \caption{A comparative analysis of two different samples.}
     \label{fig:main_figure}
\end{figure}

Key Technical Details:

  • [b] alignment: The [b] argument ensures that the subfigures are aligned along their bottom edges, which is helpful if your images have slightly different aspect ratios.
  • \hfill: This command is crucial. It acts like a spring, filling all available horizontal space between the two images to ensure they are perfectly aligned to the left and right margins.

Scientific Explanation: How LaTeX Calculates Width

Understanding the math behind \textwidth and \linewidth is key to avoiding the common "image jumping to the next page" error Simple, but easy to overlook..

  • \textwidth: This is the total width of the text block on the page.
  • \linewidth: This is the width of the current environment. Inside a minipage of 0.45\textwidth, the \linewidth becomes that 45%.

If you set two minipages to 0.5\textwidth each, you might think they would fit perfectly. On the flip side, LaTeX often interprets the space/newline between the two \begin blocks as a literal space character. 0.5 + 0.So 5 + [space] > 1. 0. This causes the second image to wrap to the next line. Consider this: to prevent this, either:

  1. But use widths that add up to less than 1. Because of that, 0 (e. g., 0.48\textwidth).
  2. Place a percent sign % immediately after the first \end{minipage} to comment out the newline character.

Comparison Table: Minipage vs. Subcaption

Feature Minipage Subcaption
Primary Use General layout/side-by-side content Formal academic sub-figures
Numbering Independent Figure numbers Parent figure with (a), (b) labels
Flexibility Can hold text, tables, and images Specifically designed for figures
Complexity Low (Built-in) Medium (Requires package)

Frequently Asked Questions (FAQ)

Why is my image appearing on a different page?

This happens because of LaTeX's floating mechanism. If there isn't enough room on the current page for the entire figure block, LaTeX moves it to the next page. You can suggest a location using position specifiers:

  • [h]: Here (try to put it exactly here).
  • [t]: Top of the page.
  • [b]: Bottom of the page.
  • [p]: Separate page for floats.
  • [htbp]: Try these in order of preference.

How do I add three images side by side?

Simply add a third minipage or subfigure and adjust the widths. For three images, a width of 0.3\textwidth for each is usually appropriate.

How can I align images vertically?

If you want images stacked vertically instead of side-by-side, simply remove the \hfill and leave a blank line (or use \vspace{...}) between the two minipage or subfigure environments

...

Conclusion
Mastering side-by-side images in LaTeX requires balancing layout commands, width calculations, and LaTeX’s floating behavior. While minipage offers simplicity and flexibility, the subcaption package provides polished, publication-ready formatting with synchronized numbering and labels. Always prioritize \hfill for horizontal alignment and use % to suppress line breaks. For complex layouts, explore TikZ or floatrow for advanced control. By understanding \textwidth and \linewidth, you can prevent common pitfalls like page breaks or misalignment. Whether crafting a scientific paper or a presentation, these tools empower you to create visually cohesive documents that adhere to academic standards. Experiment with widths, put to work packages, and let LaTeX’s precision transform your figures into professional-grade visuals.

For consistent vertical alignment across a row of mixed-size graphics, you can pass an optional alignment argument to each minipage or subfigure environment. This ensures that captions sit on the same horizontal plane even when the images above them differ in height.

How do I keep captions aligned when the images differ in height?

By default, LaTeX centers boxes vertically, which can cause captions to appear staggered if one image is taller than the other. Override this by supplying an optional letter to the environment declaration:

  • [t] — aligns the tops of the boxes.
  • [b] — aligns the bottoms (ideal when captions sit immediately below each image).
  • [c] — centers the boxes (default).

As an example, \begin{subfigure}[b]{0.45\textwidth} sets the baseline at the bottom edge of the subfigure, ensuring that the \caption text for each panel begins on the same line regardless of the image height.

Can I use a single caption for the entire group?

Yes. If you place multiple minipage environments inside one floating figure, omit individual captions and write one global \caption after the closing \end{minipage}. Looking at it differently, the subcaption package is designed specifically to give each panel a sub-caption (a), (b), etc., plus an overarching caption for the whole figure. This latter approach is preferred in most academic journals because it clearly identifies each panel for cross-referencing.

Quick-Start Template

Below is a Minimal Working Example (MWE) that combines the width, whitespace, and alignment rules discussed throughout this article. You can paste it directly into a new .tex file and compile to see a clean, two-panel layout:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}[htbp]
  \centering
  \begin{subfigure}[b]{0.48\textwidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-a}
    \caption{Initial network topology.}
    \label{fig:topology1}
  \end{subfigure}%  <-- percent sign kills the inter-column space
  \hfill
  \begin{subfigure}[b]{0.48\textwidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-b}
    \caption{Optimized network topology.}
    \label{fig:topology2}
  \end{subfigure}
  \caption{Evolution of the proposed network architecture.}
  \label{fig:network}
\end{figure}
\end{document}

Key details to note: the widths sum to 0.96\textwidth, leaving breathing room that prevents an overfull hbox; the % comment symbol suppresses the newline after the first \end{subfigure}; and [b] bottom-aligns both subfigures so their captions line up horizontally.

Conclusion

Arranging images side by side in LaTeX is ultimately an exercise in managing boxes, widths, and invisible whitespace. Which means native minipage environments offer unmatched flexibility for mixed content, while the subcaption package streamlines academic conventions with automatic panel labels and synchronized parent-level captions. By anchoring baselines deliberately, commenting out stray newlines with %, and keeping total width comfortably below \linewidth, you can sidestep these pitfalls entirely. The most common mistakes—unexpected line breaks and overfull boxes—almost always stem from overlooked spaces or overly aggressive width settings. Select the approach that matches your publication requirements, apply these spacing rules consistently, and your figures will exhibit the clarity and polish expected of professional academic documents Simple as that..

New Additions

Fresh from the Writer

Handpicked

Before You Go

Thank you for reading about How To Insert Images Side By Side In Latex. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home