82

I use the following code to include three images:

\begin{figure}[h]
\includegraphics{delete_gesture.png}
\caption{Awesome Image}
\label{fig:awesome_image}
\end{figure}

\begin{figure}[h]
\includegraphics{ok_gesture.png}
\caption{Awesome Image}
\label{fig:awesome_image}
\end{figure}

\begin{figure}[h]
\includegraphics{settings_gesture.png}
\caption{Awesome Image}
\label{fig:awesome_image}
\end{figure}

Now the images are ordered vertically. I want them horizontally. I tried to use columns or multicols but couldn't find a solution. Any hint?

4 Answers4

101

put them all together in one figure environment and the three minipages without an empty line

\documentclass[english]{article}
\usepackage[demo]{graphicx}
\usepackage{babel,blindtext}

\begin{document}

\blindtext

\begin{figure}[!htb]
\minipage{0.32\textwidth}
  \includegraphics[width=\linewidth]{delete_gesture.png}
  \caption{A really Awesome Image}\label{fig:awesome_image1}
\endminipage\hfill
\minipage{0.32\textwidth}
  \includegraphics[width=\linewidth]{ok_gesture.png}
  \caption{A really Awesome Image}\label{fig:awesome_image2}
\endminipage\hfill
\minipage{0.32\textwidth}%
  \includegraphics[width=\linewidth]{settings_gesture.png}
  \caption{A really Awesome Image}\label{fig:awesome_image3}
\endminipage
\end{figure}

\blindtext

\end{document}

enter image description here

14

Here is a solution with subfigure package. It has 2 rows and 2 columns of images. The widths are chosen such that it fits into a column of a 2-column page. I guess you get the idea.

\begin{figure}[t]
\centering
\subfigure[text]{
\includegraphics[width=.225\textwidth]{file}
}
\subfigure[text]{
\includegraphics[width=.225\textwidth]{file}
}

\subfigure[text]{
\includegraphics[width=.225\textwidth]{file}
}
\subfigure[text]{
\includegraphics[width=.225\textwidth]{file}
}

\caption{blablabla}
\label{fig:whatever}
\end{figure}

As you can see it's pretty simple to have to images/objects next to each other -- just put them into the same line. Or you can use multicol inside a figure.

Please note that subfigure is superseded by subfig which provides \subfloat command instead of \subfigure. More compatibility information is found in the subfig documentation.

ypnos
  • 587
9

I use the following technique:

\begin{figure}[h]       
    \fbox{\includegraphics{fig1.pdf}}   
    \hspace{30px}
    \fbox{\includegraphics{fig2.pdf}}
    \hspace{30px}
    \fbox{\includegraphics{fig3.pdf}}
    \caption{this is the caption}
    \label{materialflowChart}
\end{figure}

This places a thin line around each image (as it uses framebox). You can use \mbox in the same way if you don't want a frame. The \hspace{} command is a convenient way of controlling the spacing between the two images.

celenius
  • 5,274
  • Some notes: \label always comes after \caption. I think you mean '30pt' not 30px, but \hfill would be better. – Martin Scharrer Feb 04 '11 at 14:31
  • @Martin: px is the pdf unit and exactly 1 pixel –  Feb 04 '11 at 14:40
  • Thanks Martin, I did not know that about \label - I swapped the order. For some reason 30px works on my computer - I thought the px dimensions could be supplied? Is this not the case? – celenius Feb 04 '11 at 14:41
  • @Herbert: thanks, I didn't know that pdftex is adding this unit. I had a short look in the TeXbook and run a test with tex beforehand. Should have used pdftex :-) – Martin Scharrer Feb 04 '11 at 14:43
  • @Martin - Just curious, why is \hfill better? – celenius Feb 04 '11 at 14:45
  • @celenius: \hfill is not better, it depends of what you want. Often three images side by side take the whole line and it makes sense to push the outer ones strait to the line margin. If you have really small images, then it maybe better to center all and using a small gap between the images. –  Feb 04 '11 at 14:47
  • @celenius: As Herbert already said \hfill is only better if you have two or more larger images. I assumed that here. Note that in your code both images will be left aligned. As already mentioned normally a \centering is a good thing here. – Martin Scharrer Feb 04 '11 at 14:50
1

You can use the subfig package. Just keep in mind, you may need to change the width value if you're working with two or more columns

\usepackage{subfig}

\begin{figure}[!b] \centering \subfloat[text img1]{\includegraphics[width=.3\textwidth]{img1.png}} \qquad \subfloat[text img2]{\includegraphics[width=.3\textwidth]{img2.png}} \qquad \subfloat[text img3]{\includegraphics[width=.3\textwidth]{img3.png}} \caption{Caption} \label{fig:fig1} \end{figure}

Colpim
  • 11
  • Remember that the subfig package has been obsolete for a very long time, and even its authors mentioned that it should no longer be used. Its last version is almost 20 years old, and its replacement is subcaption. – Miyase Dec 02 '23 at 09:06
  • 2
    @Miyase subfigure is obsolete. subfig is still the official successor. Nevertheless I would also recommend to use subcaption. – cabohah Dec 02 '23 at 09:53
  • @cabohah subfig's own CTAN page points to subcaption as a replacement. – Miyase Dec 02 '23 at 15:15