Introduction

Two Figures Side By Side Latex

PL
idmbestpractices.ca
6 min read
Two Figures Side By Side Latex
Two Figures Side By Side Latex

two figures sideby side latex

When preparing scientific manuscripts, reports, or presentations, it is often necessary to display multiple images or diagrams side by side within a single figure environment. Consider this: this layout enhances readability, facilitates comparison, and makes optimal use of page space. In LaTeX, achieving a two figures side by side arrangement can be accomplished through several well‑documented techniques, each with its own advantages and constraints. This article explores the most common methods, provides step‑by‑step examples, and highlights best practices to confirm that the resulting figures are properly numbered, captioned, and referenced.

Introduction

LaTeX treats each figure as a floating object that can be positioned automatically by the compiler. Because of that, by default, a figure occupies the full width of the text block, which makes placing two independent graphics next to each other non‑trivial. That said, packages such as subfigure, subcaption, and the standard minipage environment allow authors to group multiple figures under a single float label, effectively creating a two figures side by side configuration. Understanding these tools is essential for anyone aiming to produce polished, publication‑ready documents in LaTeX.

Basic Approach Using the subfigure Package

The subfigure package, although now considered legacy, remains widely used due to its simplicity. It enables the creation of sub‑figures within a larger figure environment, each with its own caption and label.

\usepackage{subfigure}

\begin{figure}[ht]
  \centering
  \subfigure[First caption]{\includegraphics[width=0.48\textwidth]{image1}}%
  \hfill
  \subfigure[Second caption]{\includegraphics[width=0.48\textwidth]{image2}}%
  \caption{Overall caption describing both images}
  \label{fig:two-side-by-side}
\end{figure}

Key points

  • The width option (e.g., 0.48\textwidth) ensures that each sub‑figure occupies roughly half of the available width, leaving a small gap (\hfill) for separation.
  • Captions for sub‑figures are optional but recommended for clarity.
  • The main caption belongs to the entire float, while each sub‑caption can be referenced individually with \ref{sub:first} and \ref{sub:second} (if labels are added).

Advantages

  • Minimal code changes if existing figures already use the standard figure environment.
  • Automatic numbering of sub‑figures (e.g., “Figure 1a”, “Figure 1b”).

Limitations

  • The package is no longer maintained, and compatibility issues may arise with newer LaTeX distributions.
  • Limited flexibility in positioning and spacing.

Modern Alternative: subcaption Package

The subcaption package is the recommended replacement for subfigure. It offers more control over layout and adheres to current LaTeX best practices.

\usepackage{subcaption}

\begin{figure}[ht]
  \centering
  \begin{subfigure}{0.48\textwidth}
    \includegraphics[width=\linewidth]{image1}
    \caption{First caption}
    \label{sub:first}
  \end{subfigure}
  \hfill
  \begin{subfigure}{0.48\textwidth}
    \includegraphics[width=\linewidth]{image2}
    \caption{Second caption}
    \label{sub:second}
  \end{subfigure}
  \caption{Overall caption describing both images}
  \label{fig:two-side-by-side}
\end{figure}

Why use subcaption?

  • It separates the subfigure structure from the subcaption package, allowing finer customization.
  • The \linewidth directive ensures that each image scales to fit its container, regardless of the specified subfigure width.
  • Labels can be placed on either the subfigure or the subcaption, providing flexibility for cross‑referencing. ## Using minipage for Greater Layout Control When more complex arrangements are required—such as mixing figures with tables, equations, or text—minipage offers a dependable solution. It creates an independent box that can contain any content, including an includegraphics command.
\begin{figure}[ht]
  \centering
  \begin{minipage}[b]{0.48\textwidth}
    \centering
    \includegraphics[width=\linewidth]{image1}
    \captionof{figure}{First caption}
    \label{sub:first-minipage}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.48\textwidth}
    \centering
    \includegraphics[width=\linewidth]{image2}
    \captionof{figure}{Second caption}
    \label{sub:second-minipage}
  \end{minipage}
  \caption{Overall caption describing both images}
  \label{fig:two-side-by-side-minipage}
\end{figure}

Features

Continue exploring with our guides on write a sentence that shows the commutative property of multiplication and words that have tract in it.

  • The optional [b] argument aligns the bottom of each minipage, ensuring that captions line up neatly.
  • captionof{figure} from the caption package allows a caption without altering the float structure.
  • This method does not rely on floating sub‑figures, which can be advantageous when precise placement is critical.

Common Pitfalls and How to Avoid Them 1. Floating Issues – LaTeX may move the entire figure to a different location (e.g., the top of the next page) if the placement specifier ([ht]) cannot be satisfied. To mitigate this, use [H] from the float package to force the figure to stay exactly where it appears, though this should be used sparingly. 2. Inconsistent Caption Numbers – When sub‑figures are not properly labeled, referencing them can produce unexpected numbering. Always assign a \label to each sub‑figure and to the main figure to maintain a clear hierarchy.

  1. Overlapping Captions – If the combined width of two sub‑figures exceeds the page width, LaTeX will automatically wrap them onto separate lines. To prevent this, check that the sum of the subfigure widths (including inter‑figure spacing) is less than \textwidth.

  2. Missing Packages – Forgetting to load the required packages (subcaption, caption, float) results in compilation errors. Include all necessary \usepackage{...} statements in the preamble.

Advanced Tips for Professional Results

  • Dynamic Width Calculation: Instead of hard‑coding 0.48\textwidth, compute the width based on the number of columns in a multi‑column layout. As an example, in a two‑column document, use \columnwidth to maintain proportional scaling.

  • Consistent Font Size: Apply \small, \footnotesize, or other size commands inside sub‑figures to match the surrounding text, ensuring visual harmony.

  • **Adding a

Adding a border or background to each minipage can visually separate the images while maintaining a cohesive layout. In real terms, use the \fbox command or the tcolorbox package for more styling options. For documents with many such figures, consider defining a custom command to standardize the minipage setup, reducing code repetition and ensuring consistency.

Integrating with the subcaption Package

While the method shown avoids the subcaption package’s floating sub-figures, you can still use \subcaption within minipages to generate sub-captions that are automatically numbered (e.g., (a), (b)) and cross-referencable. Simply replace \captionof{figure} with \subcaption and adjust the main caption accordingly. This hybrid approach retains precise placement control while benefiting from hierarchical caption numbering.

Handling Varying Image Heights

When images have different aspect ratios, align minipages at the top ([t]) or center ([c]) instead of the bottom ([b]) to avoid awkward whitespace. Alternatively, use the adjustbox package’s valign option within \includegraphics to vertically align images within their minipages, creating a cleaner baseline.


Conclusion

Using minipages to place multiple images side by side offers unparalleled control over layout, making it ideal for scenarios where exact positioning is key—such as in technical reports, academic posters, or documents with strict formatting requirements. By understanding the interplay between minipage widths, caption management, and LaTeX’s float mechanism, authors can produce polished, publication-ready figures. While this method demands careful attention to spacing and package dependencies, its flexibility and reliability make it a cornerstone technique for advanced LaTeX users. Always validate the output in the final document context, as page geometry and column layouts can influence the optimal configuration. With these practices, you can master precise figure arrangement and elevate the visual quality of your LaTeX documents.

New

Latest Posts

Related

Related Posts

Thank you for reading about Two Figures Side By Side Latex. We hope this guide was helpful.

Share This Article

X Facebook WhatsApp
← Back to Home
ID

idmbestpractices

Staff writer at idmbestpractices.ca. We publish practical guides and insights to help you stay informed and make better decisions.