How do you put two and more figures(images) side by side in LaTeX?

You can understand by looking at the title. What topic am I going to discuss in this tutorial? Yes, in this tutorial I will teach you how to place more than one figure or image side by side.

But, before we jump directly to solutions there are some concepts to clear. Because this tutorial is based on the following three concepts.

1. Multicolumn Page Layout
2. Width Parameter – \textwidth
3. Width Parameter – \linewidth

Multicolumn Page Layout

In a multi-column layout, your document (or a portion of it) is divided into multiple columns, akin to newspaper columns. When placing images side by side, you are essentially creating a multi-column layout for those images. Then place the figures independently on each column and you will see that the figures are automatically placed side by side.

Understanding this concept helps you control alignment and spacing between these ‘columns’ of images, ensuring that the images are positioned exactly as you want relative to each other and to the text.

Width Parameter – \textwidth

Divided a page into multi-column page layout, okay. But, have you thought about how much space each column will occupy or how to divide one column into 30 percent and the other into 70 percent, also how to increase the space separation between columns, and how each column will take equal space?

Answer to each of the above questions is hidden within a \textwidth command, which is a highly useful length command that represents width of text area on the page.

When representing width of a column, total length must be divided into percentages. Total length is defined by this command.

For example, width of one column is X percent and other is Y percent.

ColumnX Width=(X/100)\textwidth ColumnY Width=(Y/100)\textwidth
Column50 Width=.5\textwidth Column50 Width=.5\textwidth
Column30 Width=.3\textwidth Column70 Width=.7\textwidth

Width Parameter – \linewidth

\linewidth command in LaTeX is used to represent current width of line of text.

When you are working inside a narrower environment (like a minipage, a column in a multi-column layout, or a list item), \linewidth will be equal to width of that environment, not the full width of page’s text area.

When placing images side by side, \linewidth is a valuable command to control width of each image relative to containing environment (like a minipage, column, or list environment).

Same use in percentages as in \textwidth. like \linewidth, .5\linewidth, .25\linewidth etc.

Use subfigure environment

A subfigure is an environment that is used within a figure environment. But, the width option must be passed with this environment. In this case, the best practice is to use width as a percentage. Also, you can use other length units(cm, em, pt, etc), making figure placement side-by-side difficult.

\documentclass[11pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{graphicx,subcaption,lipsum}

\begin{document}

\begin{figure}[h]
  \begin{subfigure}{.5\textwidth}
  \centering
    \includegraphics[width=1\linewidth]{image.jpg}
    \caption{First subfigure}
  \end{subfigure}%
  \begin{subfigure}{.5\textwidth}
  \centering
    \includegraphics[width=1\linewidth]{image.jpg}
    \caption{Second subfigure}
  \end{subfigure}
  \caption{Main caption}
\end{figure}

\lipsum[1][1-8]

\begin{figure}[h]
  \begin{subfigure}{.5\textwidth}
  \centering
    \includegraphics[width=.9\linewidth]{image.jpg}
    \caption{First subfigure}
  \end{subfigure}%
  \begin{subfigure}{.5\textwidth}
  \centering
    \includegraphics[width=.9\linewidth]{image.jpg}
    \caption{Second subfigure}
  \end{subfigure}
  \caption{Main caption}
\end{figure}

\lipsum[3][1-8]

\begin{figure}[h]
\centering
  \begin{subfigure}{.3\textwidth}
    \includegraphics[width=.9\linewidth]{image.jpg}
    \caption{First subfigure}
  \end{subfigure}%
  \begin{subfigure}{.3\textwidth}
    \includegraphics[width=.9\linewidth]{image.jpg}
    \caption{Second subfigure}
  \end{subfigure}%
   \begin{subfigure}{.3\textwidth}
    \includegraphics[width=.9\linewidth]{image.jpg}
    \caption{Third subfigure}
  \end{subfigure}
\caption{Main caption}
\end{figure}

\end{document}

Output :

You can add captions for each subfigure with the sub-caption package.

Use subfloat command by subfig package

\subfloat command comes from subfig package in LaTeX, which provides support for including multiple figures within a single-figure table environment, each with its own separate caption (often called a sub-caption).

This is extremely useful when you want to group a series of related images into one figure environment.

\documentclass[11pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{xcolor,graphicx,subfig,lipsum}
\begin{document}
\pagecolor{yellow!15}
\lipsum[1][1-9]

\begin{figure}[h]
 \centering
  \subfloat[First subfigure]{\includegraphics[width=.48\linewidth]{image.jpg}}
  \subfloat[Second subfigure]{\includegraphics[width=.48\linewidth]{image.jpg}}
  \caption{Without space}
\end{figure}

\lipsum[2][1-7]

\begin{figure}[h]
  \centering
  \subfloat[First subfigure]{\includegraphics[width=.49\linewidth]{image.jpg}}\hfill
  \subfloat[Second subfigure] {\includegraphics[width=.49\linewidth]{image.jpg}}
  \caption{Add space}
\end{figure}

\lipsum[2-3]

\begin{figure}[h]
  \centering
  \subfloat[First subfigure]{\includegraphics[width=.33\linewidth]{image.jpg}}\hfill
  \subfloat[Second subfigure] {\includegraphics[width=.33\linewidth]{image.jpg}} \hfill
 \subfloat[Third subfigure] {\includegraphics[width=.33\linewidth]{image.jpg}}
  \caption{Add space}
\end{figure}

\lipsum[4][1-8]

\end{document}

Output :

\subfloat take an optional argument in a square bracket [], which is used to define caption for this specific subfigure.

minipage environment

In simple terms, minipage environment will create a box in which you can place different types of elements like text, figures, tables, etc.

To place side-by-side figures in this environment, you must first create a side-by-side multicolumn box with minipage.

\documentclass[11pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{graphicx,xcolor,subcaption,lipsum}
\begin{document}
\pagecolor{green!7!white}

\lipsum[1][1-5]
\vspace{.5cm}

\begin{figure}
\centering
\begin{minipage}{.5\textwidth}
  \includegraphics[width=1\linewidth]{image.jpg}
  \caption{Caption for first figure.}
\end{minipage}%
\begin{minipage}{.5\textwidth}
  \includegraphics[width=1\linewidth]{image.jpg}
  \caption{Caption for second figure.}
\end{minipage}
\end{figure}

\vspace{.5cm}
\lipsum[2][1-5]
\vspace{.5cm}

% Use without float env

\noindent\begin{minipage}{.5\textwidth}
\centering
  \includegraphics[width=.9\linewidth]{image.jpg}
  \captionof{figure}{Caption for first fig}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
  \includegraphics[width=.9\linewidth]{image.jpg}
  \captionof{figure}{Caption for Second fig}
\end{minipage}

\vspace{.5cm}
\lipsum[2][1-5]
\vspace{.5cm}

\noindent\begin{minipage}{.4\textwidth}
\centering
  \includegraphics[width=.9\linewidth]{image.jpg}
\end{minipage}%
\begin{minipage}{.6\textwidth}
\centering
  \includegraphics[width=.9\linewidth]{image.jpg}
\end{minipage}

\end{document}

Output :

For example, suppose you are creating two-column boxes. In this case, you need to define width of both column layouts. And parameter to measure width of an entire page is 1\textwidth or \textwidth. If you want to make the width of two columns equal then you have to pass .5\textwidth with environment.

In the same way, working with 3 or 4 columns, if you want to divide them equally horizontally, then they will be wide in .33\textwidth and .25\textwidth.

multicol package

multicols environment is primarily for text rather than figures. However, if you still want to place figures inside, you won’t be able to use the standard \caption command directly within multicols because the figure environment is a float, and you can’t use floats inside multicols.

A common way to overcome this limitation is to use the caption package, which provides a \captionof  command. This lets you add captions outside of float environments.

\documentclass[11pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{graphicx,xcolor,lipsum,multicol,caption}
\begin{document}
\pagecolor{red!7!white}
\lipsum[1][1-7]

\begin{multicols}{2}
 \centering
   \includegraphics[width=.98\linewidth]{image.jpg}
   \captionof{figure}{Caption of Subfig }
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
   \captionof{figure}{Caption of Subfig}
\end{multicols}

\begin{multicols}{3}
 \centering
   \includegraphics[width=.98\linewidth]{image.jpg}
   \captionof{figure}{Subfig X}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
   \captionof{figure}{Subfig Y}
   \columnbreak
  \includegraphics[width=.98\linewidth]{image.jpg}
   \captionof{figure}{Subfig Z}
\end{multicols}

\begin{multicols}{4}
 \centering
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
\end{multicols}

\begin{multicols}{5}
\centering
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
\end{multicols}

\lipsum[3][1-7]

\begin{multicols}{6}
 \centering
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
   \columnbreak
   \includegraphics[width=.98\linewidth]{image.jpg}
\end{multicols}

\lipsum[5]
\end{document}

Output :

Use includegraphics in sequence

No external packages, environments, or commands are required. You can complete this task by placing this \includegraphics side by side in sequence.

In this case, you can add main caption but not sub caption.

\documentclass[11pt]{article}
\usepackage{graphicx,xcolor,lipsum}
\usepackage[margin=1.5cm]{geometry}
\begin{document}
\pagecolor{red!5}

\lipsum[1][1-8]

\begin{figure}[h]
\centering
\includegraphics[width=.5\textwidth]{image.jpg}%
\includegraphics[width=.5\textwidth]{image.jpg}
\caption{Main Caption}
\end{figure}

\lipsum[2][1-8]

\begin{figure}[h]
\centering
\includegraphics[width=.4\textwidth]{image.jpg}\quad
\includegraphics[width=.4\textwidth]{image.jpg}
\caption{Main Caption}
\end{figure}

\lipsum[3][1-10]

\begin{figure}[h]
\centering
\includegraphics[width=.35\textwidth]{image.jpg}\hspace{1cm}
\includegraphics[width=.35\textwidth]{image.jpg}
\end{figure}

\lipsum[4][1-5]

\end{document}

Output :

Using tabular

While tabular is primarily designed for tables, it can be used creatively to place content, including figures, side by side. Not limited to two figures. You can use it to align multiple images in rows and columns, creating a grid of images.

\documentclass[11pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{graphicx,lipsum}
\begin{document}

\lipsum[1][1-7]

\begin{figure}[h]
\centering
\begin{tabular}{cc}
  \includegraphics[width=0.47\textwidth]{image.jpg} & \includegraphics[width=0.47\textwidth]{image.jpg} \\
  Caption for first image & Caption for second image \\
\end{tabular}
\caption{Main caption for both images}
\end{figure}

\lipsum[2][1-8]

\begin{figure}[h]
\centering
\begin{tabular}{cc}
  \includegraphics[width=0.4\textwidth]{image.jpg} & \includegraphics[width=0.4\textwidth]{image.jpg} \\
  Caption for first image & Caption for second image \\
\end{tabular}
\caption{Main caption for both images}
\end{figure}

\lipsum[3][1-8]

\begin{figure}[h]
\centering
\begin{tabular}{ccc}
  \includegraphics[width=0.3\textwidth]{image.jpg} & \includegraphics[width=0.3\textwidth]{image.jpg} &
  \includegraphics[width=0.3\textwidth]{image.jpg} \\
  Caption for first image & Caption for second image  & Caption for Thrird image\\
\end{tabular}
\caption{Main caption for all images}
\end{figure}

\end{document}

Output :

Conclusion

Placing figures side by side in a LaTeX document is achievable through various methods, each with its own advantages. The subfigure environment and subfloat command from subfig package offers structured and flexible approaches, respectively.

For more control, minipage environment, multicol package, and tabular environment provides options to integrate figures within different multi-column layouts.

Md Jidan Mondal

LaTeX expert with over 10 years of experience in document preparation and typesetting. Specializes in creating professional documents, reports, and presentations using LaTeX.

Leave a Comment

Your email address will not be published. Required fields are marked *