When creating documents that require precise mathematical formatting, LaTeX is the go-to tool for many academics, researchers, and students. One common need in such documents is to display two figures side by side, whether they are graphs, diagrams, or images. This not only saves space but also allows for direct visual comparison, which is especially useful in scientific and technical writing It's one of those things that adds up. But it adds up..
In LaTeX, the process of arranging two figures side by side is straightforward, but it does require a basic understanding of how LaTeX handles floats and positioning. The most common method involves using the figure environment in combination with the subfigure or subcaption package. These packages are specifically designed to help manage multiple images or plots within a single figure, giving you control over their layout and captions.
To begin, you'll need to include the necessary package in your LaTeX preamble. If you're using the subcaption package, you would add:
\usepackage{subcaption}
The subcaption package is preferred in modern LaTeX documents because it is more flexible and better maintained than the older subfigure package. Once the package is loaded, you can create a figure environment and use the subfigure environment (or subcaptionbox if you prefer) to place your two images side by side.
Here's a simple example of how to arrange two figures side by side using the subcaption package:
\begin{figure}
\centering
\begin{subfigure}{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{image1}
\caption{First image}
\label{fig:first}
\end{subfigure}
\hfill
\begin{subfigure}{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{image2}
\caption{Second image}
\label{fig:second}
\end{subfigure}
\caption{Two figures side by side}
\label{fig:twofigs}
\end{figure}
In this example, each subfigure environment is set to take up 45% of the text width, leaving a small gap between them. Even so, the \hfill command ensures that the two subfigures are evenly spaced within the figure environment. Each subfigure can have its own caption and label, and the entire group can be referenced as a single figure using the main \caption and \label Small thing, real impact..
This changes depending on context. Keep that in mind That's the part that actually makes a difference..
If you prefer not to use the subcaption package, you can achieve a similar result using the minipage environment. This method is a bit more manual but offers greater flexibility:
\begin{figure}
\centering
\begin{minipage}[b]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{image1}
\captionof{figure}{First image}
\end{minipage}
\hfill
\begin{minipage}[b]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{image2}
\captionof{figure}{Second image}
\end{minipage}
\end{figure}
The minipage approach requires the caption package for the \captionof command, which allows you to add captions to figures or tables outside of their standard environments. This method is useful if you want more control over the exact positioning and sizing of your figures That's the part that actually makes a difference. Worth knowing..
When working with figures in LaTeX, don't forget to remember that LaTeX treats figures as "floats," meaning it will automatically try to place them in the best location on the page. Sometimes, this can lead to figures appearing in unexpected places. To have more control over the placement, you can use placement specifiers like [h] (here), [t] (top), [b] (bottom), or [p] (on a separate page).
\begin{figure}[h]
% your figure code here
\end{figure}
The [h] specifier tells LaTeX to try to place the figure exactly where it appears in the source code. On the flip side, LaTeX may still override this if it cannot fit the figure in the desired location The details matter here..
For those working with TikZ or other graphics packages, arranging figures side by side follows the same principles. You can include TikZ pictures or plots directly within the subfigure or minipage environments, allowing for complex diagrams or graphs to be displayed next to each other.
The short version: arranging two figures side by side in LaTeX is a common and manageable task. Whether you choose to use the subcaption package for its simplicity and modern features, or the minipage environment for greater control, the process is straightforward once you understand the basics. By mastering these techniques, you can create professional, well-organized documents that effectively present visual information side by side, enhancing the clarity and impact of your work It's one of those things that adds up..
To further enhance the arrangement of figures in LaTeX, consider the adjustbox package, which simplifies scaling and positioning images within containers. Because of that, this package allows you to automatically adjust the size of images to fit within a specified width or height, ensuring consistency across subfigures. For example:
\usepackage{adjustbox}
\begin{figure}[h]
\centering
\begin{minipage}[b]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{image1}
\caption{First image}
\end{minipage}
\hfill
\begin{minipage}[b]{0.
You'll probably want to bookmark this section.