How to Include Side-by-Side Images in LaTeX

LaTeX is a typesetting document system used to create technical documents. Images can be added to those documents using the graphicx package. Here’s how. 

Published on Oct. 10, 2024
Research reviewing an academic document on comptuer
Image: Shutterstock / Built In
Brand Studio Logo

LaTeX is a typesetting document system that is most commonly used to produce technical and scientific documents. In this article, we will focus on the package graphicx, which allows us to add images often included in articles. We will provide a detailed explanation of how to insert side-by-side images using the figure and minipage environments.

How to Include Two Pictures Side-by-Side in LaTeX

Two pictures can be included side-by-side in LaTeX using the graphicx package. This can be done using the figure or minipage environment. The figure environment allows images to be added using the includegraphics command. The minipage environment allows images to be added as mini pages so that you can include multiple captions. 

There are several reasons why you might want to add images side-by-side. Maybe you want to contrast two images, group images that belong to the same classification or just save space on your document. 

Let’s take a look at how that works. 

 

Side-by-Side Images: The Figure Environment

To start, don’t forget that you need to import the graphicx package in the preamble.

First, let’s begin with the figure environment. We just need to add the images in different includegraphics commands.

Before the example, there are a couple important factors to keep in mind:

  • The total width of all the figures must not exceed the page width. Otherwise, the figures will be inserted one below other.
  • There must not be any line breaks between the includegraphics command.

An example is:

Code to add two pictures side-by-side in LaTeX using the figure environment.
Code to add two pictures side-by-side in LaTeX using the figure environment. | Image: Jesús Adrián Montesinos Correa

This code produces:

Image produced from the code
Image produced from the code. | Image: Jesús Adrián Montesinos Correa

We can use \hfill to separate the figures by the available horizontal space.

Figure environment code with /hfill applied.
Figure environment code with \hfill applied. | Image: Jesús Adrián Montesinos Correa

This code produces:

Image produced from the code.
Image produced from the code. | Image: Jesús Adrián Montesinos Correa

While the difference may not seem so big here, you can try it with different sized images to notice a bigger difference. That is how you can put side-by-side images in LaTeX, but did you notice: There is just one caption for all of the images.

If you want to explain or provide a caption for each image, there is a way to do it.

More on Data SciencePython Image Processing: A Tutorial

 

Side-by-Side Images in LaTeX: The minipage Environment With Captions

Theminipage environment, as its name suggests, creates a mini page inside the page. You can configure its width and the content it will have:

\begin{minipage}[position]{width}
content
\end{minipage}

Where position could be

  • c center
  • t at the top
  • b at the bottom

And width can be:

  • An explicit measure, for example: 3 cm or 8 cm.
  • A portion of the width of the page, we can do it with X\linewidth where X is the percentage of the page, 0<X<1, for example, `0.5\linewidth* is 50 percent of the page’s width.

For example:

Minipage environment code.
Minipage environment code. | Image: Jesús Adrián Montesinos Correa

This code produces:

Minipage environment image produced from code.
Minipage environment image produced from code. | Image: Jesús Adrián Montesinos Correa
A tutorial on how to add two pictures side-by-side in LaTeX. | Video: PMC Tech

More on Software EngineeringHow to Configure a Custom Zsh Alias

Images and Minipage

If you want to add multiple images with a different caption, you need to put those in the minipage environment.

Remember that you need to have the graphicx package imported. You can add a general caption, just before the \end{figure} command:

For example:

Code to add a general caption on LaTeX.
Code to add a general caption on LaTeX. | Image: Jesús Adrián Montesinos Correa

This code produces:

image produced from code
image produced from code. | Image: Jesús Adrián Montesinos Correa

And that’s everything you need to know to include side-by-side images in LaTeX.

Frequently Asked Questions

LaTeX is a typesetting document system that is most commonly used to produce technical and scientific documents.

You can add two images side-by-side in LaTex using the graphicx package. You can use the following features to adjust the images:

  • /hfill allows the images to be separated by horizontal space.
  • Minipage environment creates a mini page within the LaTeX document where you can add individual captions for each image.
  • Position sets the position for the image.
  • Width sets the width.
Explore Job Matches.