2

When I import several images into LaTeX, the default is for the images to appear directly below the previous image. How can I display the pictures (even as many as five) side by side on the same row?

Also, how can I have three rows of the images displayed one right after the other?

1
  • 1
    No, that's not the default. Commented Apr 25, 2014 at 0:21

1 Answer 1

7

I thing there's a misunderstanding; the default for \includegraphics is not to place one image below the other, it is to place them where you tell LaTeX to place them; \includegraphics places the image at the indicated place.

Take a look at the following example showing two cases: in the first case, two images were placed one nest to the other, with no space in between (as you can see even if the total width of the images exceeds the width of the text area, the images will be placed one next to the other); in the second case, since a blank line was left between the \includegraphics commands, the images will appear one below the other (a blank line tantamounts to \par, so the second image starts its own paragraph):

\documentclass{article}
\usepackage{graphicx}
\usepackage{showframe}% to show the page layout

\begin{document}

Two images one after the other even if they protrude into the right margin

{\centering
\includegraphics[width=.6\textwidth,height=3cm]{example-image-a}%
\includegraphics[width=.6\textwidth,height=3cm]{example-image-a}\par
}

\vspace*{1cm}

Two images, one below the other since a blank line (i.e., a \verb+\par+ command) was left in between:

{\centering
\includegraphics[width=.6\textwidth,height=3cm]{example-image-a}

\includegraphics[width=.6\textwidth,height=3cm]{example-image-a}\par
}

\end{document}

enter image description here

Depending on your settings the images can be placed in any desired arrangement. Of course, the ideal for rows of images is to take the precaution (for example, by controlling the width of the images) to have a total width that doesn't exceed the width of the text area (but even if required, you can exceed that dimension using a \makebox, for example).

A little example:

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\noindent\begin{minipage}{\textwidth}
\centering
\includegraphics[width=.15\textwidth]{example-image-a}\hfill
\includegraphics[width=.15\textwidth]{example-image-a}\hfill
\includegraphics[width=.15\textwidth]{example-image-a}\hfill
\includegraphics[width=.15\textwidth]{example-image-a}\hfill
\includegraphics[width=.15\textwidth]{example-image-a}
\end{minipage}

\vspace{1cm}

\noindent\begin{minipage}{\textwidth}
\centering
\includegraphics[width=.15\textwidth]{example-image-a}\\
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\\
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\\
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}
\end{minipage}

\vspace{1cm}

\noindent\begin{minipage}{\textwidth}
\centering
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\\
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\\
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}\quad
\includegraphics[width=.15\textwidth]{example-image-a}
\end{minipage}

\end{document}

enter image description here

In the example above I used a (not really required) static environment (minipage) to place the groups of images, but the same applies to a floating figure environment (see the example below).

If you are interested in treating the images as sub-images, some packages give you additional useful features to provide, for example, captions for them:

A little example using \subcaptionbox from the subcaption package to produce a 3x3 array of subfigures, each one having its caption, and a general caption for the whole figure:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\subcaptionbox{sub 1\label{fig:testa}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 2\label{fig:testb}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 3\label{fig:testc}}{\includegraphics[width=.15\textwidth]{example-image-a}}\par\medskip
\subcaptionbox{sub 4\label{fig:testd}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 5\label{fig:teste}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 6\label{fig:testf}}{\includegraphics[width=.15\textwidth]{example-image-a}}\par\medskip
\subcaptionbox{sub 7\label{fig:testg}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 8\label{fig:testh}}{\includegraphics[width=.15\textwidth]{example-image-a}}\quad
\subcaptionbox{sub 9\label{fig:testi}}{\includegraphics[width=.15\textwidth]{example-image-a}}
\caption{a figure with nine subfigures in a $3\times 3$ array}
\label{fig:test}
\end{figure}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .