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?
-
2There has been a lot of this going around lately. I prefer using a tabular to subfigure. See http://tex.stackexchange.com/questions/147585/append-centering-to-beginsubfigure-from-subcaption-package/147641#147641 – John Kormylo Dec 05 '13 at 02:55
-
how is this question different from http://tex.stackexchange.com/questions/5769/two-figures-side-by-side ? – Charlie Parker Oct 25 '16 at 21:35
-
The conflict between \subfig and \hyperref is real. – David Crosswell May 19 '20 at 20:57
6 Answers
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}

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}

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}

Pros and Cons of the Approaches
- 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.
- The first one which uses the
minipageenvironment 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. - The results from
subfigandsubcaptionare very similar. Though each has its own way of usage. However, there are reports onsubfignot working properly withhyperref. This question provides an excellent discussion on the comparative analysis onsubcaptionvs.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.
-
1Could you provide the pros and cons for each option? Or they are exactly identical? – kiss my armpit Dec 05 '13 at 07:28
-
1@DonutE.Knot Updated my answer. Thanks for pointing out the issue, that helped me make my answer better. – Masroor Dec 05 '13 at 10:33
-
(+1) great answer. You can also use floatrow for this task. Can be a bit painful but helps a lot if you have special needs in caption positioning. – masu Dec 05 '13 at 17:05
-
Note that blank lines before or after the
\hfillwill break the layout. – V02460 Nov 02 '17 at 16:27 -
For the first method, how to vertically space them more apart? When adding more subfigures until they move into the next row, what happens is there is no space between them and it looks awkward. – PlsWork Dec 06 '17 at 21:06
-
@AnnaVopureta Perhaps you will want to add vertical space (rubber length or fixed) commands at appropriate places. – Masroor Dec 07 '17 at 00:35
-
@Masroor What command do you suggest? I ended up using the solution seperately two times. The result are four neatly spaced images, this should work for arbitrarily many columns. – PlsWork Dec 07 '17 at 10:32
-
@AnnaVopureta There is no ready-made solution for the scenario you described. So far as I gather from your brief description, you will want to put the images in some tabular cells. – Masroor Dec 08 '17 at 01:14
-
The solution with minipage may give problems with the two separate captions. Here it is suggested to use
\RawFloatsright after\begin{figure}and it worked nicely for me. – GRquanti Sep 12 '20 at 13:48
These solutions are too complicated IMHO, you don't need to install any new packages.
\begin{figure}[h]
\begin{tabular}{ll}
\includegraphics[scale=1]{Figures/Race.png}
&
\includegraphics[scale=0.4]{Figures/Bearing.png}
\end{tabular}
\caption{Left: Diagram of angular contact bearing \cite{NBCBearing}.
Right: Disassembled bearing}
\label{Fig:Race}
\end{figure}
- 1,799
-
6Welcome to the site! To be fair, half the solutions above do not require any extra packages beyond
graphicx. You could note that withpcolumns one can also add captions for each image, if desired. – Torbjørn T. Aug 21 '15 at 06:16
The MWE package offers a nice solution:
\documentclass{article}
\usepackage{mwe}% or load ’graphicx’ and ’blindtext’ manually
\begin{document}
\blindtext
\begin{figure}
\includegraphics[width=.48\linewidth]{example-image-a}\hfill
\includegraphics[width=.48\linewidth]{example-image-b}
\caption{MWE to demonstrate how to place to images side-by-side}
\end{figure}
\blindtext
\end{document}
- 6,690
- 5
- 26
- 47
-
Insted of beside each other I want to put many figure back to back in different pages, then what should I do ? – Deepesh Patel Aug 06 '15 at 06:29
-
The conflict with subfig and \hyperref does exist: it's not just a rumor, which is why I prefer subcaption as I almost invariably need hyperref.
Also, \begin{subfigure}[b]{0.475\textwidth} should give a cleaner finish, still with plenty of space between the figures.
Place:
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
in the preamble.
- 296,517
- 395
I would recommend using the tikz package. this answers your question in the most basic form, with for instance:
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node [anchor=north west] (imgA) at (.05\linewidth, .050\linewidth){\includegraphics[width=.5\linewidth]{figA.pdf}};
\node [anchor=north west] (imgB) at (.05\linewidth, .500\linewidth){\includegraphics[width=.\linewidth]{figB.pdf}};
\end{tikzpicture}
\end{document}
One advantage is that you can place any number of figure, but also place easily letters to identify the figures:
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node [anchor=north west] (imgA) at (.05\linewidth, .050\linewidth){\includegraphics[width=.5\linewidth]{figA.pdf}};
\draw [anchor=north west] (0., .000\linewidth) node {(A)};
\node [anchor=north west] (imgB) at (.05\linewidth, .500\linewidth){\includegraphics[width=.\linewidth]{figB.pdf}};
\draw [anchor=north west] (0., .500\linewidth) node {(A)};
\end{figure}
\end{document}
An example of use can be found in this paper's LaTeX code, at page 4 of the PDF:
You may need to tune the position of each object manually to get the appropriate result.
- 1,247
Not an exact solution, but a workaround. I wasn't happy with how much blank space Latex allowed between the two images. So I copied both images into MS word (or Google Docs), arranged them side-by-side, and used the Snipping Tool to create a "single" picture. What's seen below is a single .png file which is much easier to insert.
- 11
-
9If the original pictures are vector graphics, then converting to a bitmap like PNG would decrease image quality. – Heiko Oberdiek Jul 19 '16 at 16:44
-
1this solution can be improved: instead of using pixel based image editors, it is better to use vector based image editors. My suggestion is to use LibreOffice Draw and save the image as PDF – Sadegh Jan 01 '17 at 15:49
-
4LaTeX can do virtually whatever you instruct it to do, you needn't use any third-party software to achieve what you want in LaTeX. Blank space, alignment, size, etc. can all be adjusted from within LaTeX quite easily. – AboAmmar Sep 22 '17 at 06:57

