[Tex/LaTex] Putting two images beside each other

floatsgraphicspositioning

If I want to put two images beside each other, what should I do? I have inserted a figure. But, rather than having the next figure on a new line, I want it to be beside the already inserted figure. How can I do that?

Best Answer

Actually there are a number of ways of achieving what you are asking for.


Without Using Any Package

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\begin{figure}[!tbp]
  \centering
  \begin{minipage}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{flower1.jpg}
    \caption{Flower one.}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{flower2.jpg}
    \caption{Flower two.}
  \end{minipage}
\end{figure}

\end{document}

enter image description here


Using Packages

You can use either subfig or subcaption.

Using subfig

\documentclass{article}

\usepackage{graphicx}
\usepackage{subfig}

\begin{document}

\begin{figure}[!tbp]
  \centering
  \subfloat[Flower one.]{\includegraphics[width=0.4\textwidth]{flower1.jpg}\label{fig:f1}}
  \hfill
  \subfloat[Flower two.]{\includegraphics[width=0.4\textwidth]{flower2.jpg}\label{fig:f2}}
  \caption{My flowers.}
\end{figure}

\end{document}

enter image description here

Using subcaption

\documentclass{article}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}[!tbp]
  \begin{subfigure}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{flower1.jpg}
    \caption{Flower one.}
    \label{fig:f1}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{flower2.jpg}
    \caption{Flower two.}
    \label{fig:f2}
  \end{subfigure}
  \caption{My flowers.}
\end{figure}

\end{document}

enter image description here


Pros and Cons of the Approaches

  1. It is actually difficult to call one method superior over the other. Which one you want to use will depend on the result you are expecting. So, see the results presented above and choose yourself.
  2. The first one which uses the minipage environment is actually very simple. But as you can see the figures are number individually. If want to present a group of related figures, it may not be the one you are looking for.
  3. The results from subfig and subcaption are very similar. Though each has its own way of usage. However, there are reports on subfig not working properly with hyperref. This question provides an excellent discussion on the comparative analysis on subcaption vs. subfig.

Further Reading

In order to get a better understanding of the placement and width controlling issues, I strongly suggest the you go through the documentation of the above two packages (subfig and subcaption). These documentations contain some excellent hints and examples.

Also, for comprehending the solutions of related issues, these questions (A, B, C, D, E, F) are worth taking a look at.

Related Question