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?
[Tex/LaTex] Putting two images beside each other
floatsgraphicspositioning
Related Solutions
You can use the subcaption
package (a powerful companion to the caption package):
\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\DeclareCaptionFormat{subfig}{\figurename~#1#2#3}
\DeclareCaptionSubType*{figure}
\captionsetup[subfigure]{format=subfig,labelsep=colon,labelformat=simple}
\begin{document}
\begin{figure}[!ht]
\begin{subfigure}[b]{.5\linewidth}
\centering
\rule{4cm}{3cm}
\caption{A subfigure}
\label{fig:1a}
\end{subfigure}%
\begin{subfigure}[b]{.5\linewidth}
\centering
\rule{4cm}{3cm}
\subcaption{Another subfigure}
\label{fig:1b}
\end{subfigure}
\caption{A figure with two subfigures}
\label{fig:1}
\end{figure}
\end{document}
Box them together and look out for trailing spaces/line breaks:
\begin{figure}[h]
\centerline{%
\includegraphics[width=0.5\textwidth]{CircleTemplate.eps}%
\includegraphics[width=0.5\textwidth]{CircleOlimpicStarting.eps}%
}%
\centerline{%
\includegraphics[width=0.5\textwidth] {CircleOlimpicFinishing.eps}%
\includegraphics[width=0.5\textwidth] {CircleOlimpicFinishingWithNoise.eps}%
}%
\caption{Some long long caption}
\label{fig:OlimpicCircleTT1}
\end{figure}
Another alternative would be to use a tabular
with {@{}c@{}c@{}}
as column specification to avoid any inter-column spaces.
Note: The line endings in the source code will be taken as space if you don't use %
to comment them out. So basically you ask for <image with 50% textwidth><space><image with 50% textwidth>
which is slightly wider than the text width and therefore will be broken into two lines.
If you want some space between the images you can use the following:
\begin{figure}[h]
\makebox[\textwidth]{%
\includegraphics[width=0.49\textwidth]{image1}%
\hfill
\includegraphics[width=0.49\textwidth]{image2}%
}\\[0.5cm]% If you want some vertical space
\makebox[\textwidth]{%
\includegraphics[width=0.49\textwidth]{image3}%
\hfill
\includegraphics[width=0.49\textwidth]{image4}%
}%
\caption{Some long long caption}
\label{fig:OlimpicCircleTT1}
\end{figure}
Best Answer
Actually there are a number of ways of achieving what you are asking for.
Without Using Any Package
Using Packages
You can use either subfig or subcaption.
Using
subfig
Using
subcaption
Pros and Cons of the Approaches
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.subfig
andsubcaption
are very similar. Though each has its own way of usage. However, there are reports onsubfig
not working properly withhyperref
. This question provides an excellent discussion on the comparative analysis onsubcaption
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.