Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
Two figures side by side

I want to place 2 images side by side in LaTeX. I have 2 .png files and I don't understand how to do it in LaTeX. I have tried many ways but could not get a good result.

share|improve this question
    
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Torbjørn T. Dec 8 '11 at 14:25
add comment

migrated from stackoverflow.com Dec 8 '11 at 14:23

This question came from our site for professional and enthusiast programmers.

marked as duplicate by cmhughes, Werner, Paulo Cereda, Seamus, lockstep Dec 8 '11 at 18:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4 Answers

For two independent side-by-side figures, you can use two minipages inside a figure enviroment; for two subfigures, I would recommend the subcaption package with its subfigure environment; here's an example showing both approaches:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.4\linewidth]{image1}
  \caption{A subfigure}
  \label{fig:sub1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.4\linewidth]{image1}
  \caption{A subfigure}
  \label{fig:sub2}
\end{subfigure}
\caption{A figure with two subfigures}
\label{fig:test}
\end{figure}

\begin{figure}
\centering
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=.4\linewidth]{image1}
  \captionof{figure}{A figure}
  \label{fig:test1}
\end{minipage}%
\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=.4\linewidth]{image1}
  \captionof{figure}{Another figure}
  \label{fig:test2}
\end{minipage}
\end{figure}

\end{document}

enter image description here

The demo option for graphicx was used only to make my example compilable for everyone; you shouldn't use that option in your actual code.

share|improve this answer
    
right... but where do you say minipage in your latex code? –  drN Aug 29 '12 at 18:05
1  
@DNA inside the second figure environment there are two minipages; one for each of the (independent) images. –  Gonzalo Medina Aug 29 '12 at 20:42
11  
That % at the end of \end{subfigure} seems to be very important if you want the images to be side by side. :) –  Roman Luštrik May 2 '13 at 13:40
3  
@RomanLuštrik yes; it really is important; not suppressing it will cause a spurious blank space to be added, the total length will surpass \textwidth and the figures will end up not side-by-side. –  Gonzalo Medina May 2 '13 at 13:43
1  
If one of the images have a multi-line caption then the images are not aligned side-by-side. In this case, use [t] option after \begin{subfigure}. –  bkarpuz Jun 4 '13 at 7:04
show 4 more comments

You could use the subfigure package:

\begin{figure}
\hfill
\subfigure[Title A]{\includegraphics[width=5cm]{img1}}
\hfill
\subfigure[Title B]{\includegraphics[width=5cm]{img2}}
\hfill
\caption{Title for both}
\end{figure}

Or try this use the subfig package with \usepackage{subfig}:

\begin{figure}
\centering
\parbox{5cm}{
\includegraphics[width=5cm]{img1}
\caption{First.}
\label{fig:2figsA}}
\qquad
\begin{minipage}{5cm}
\includegraphics[width=5cm]{img2}
\caption{Second.}
\label{fig:2figsB}
\end{minipage}
\end{figure}

Your question would be better on TeX-LaTeX StackExchange.

share|improve this answer
    
Thanks rekire. But the images are not being displayed. –  nikhil Dec 8 '11 at 11:40
    
You have to change the img1 and img2 –  rekire Dec 8 '11 at 11:42
    
Ya rekire. It does not work for me –  nikhil Dec 8 '11 at 11:43
1  
The second example does note make use of the subfig package at all!? –  Axel Sommerfeldt Dec 8 '11 at 16:23
1  
I think it would be better not to recommend using the obsolete package subfigure. –  Gonzalo Medina Dec 8 '11 at 16:27
show 3 more comments
\usepackage{subfig}

The PDF documentation with lots of examples can be found here: http://www.stud.math.ntnu.no/kurs/latexdocs/subfig.pdf

Note that you'll see a lot of references to "subfigure" on the net, but that's outdated now.

Here is a small example taken from the documentation

\documentclass[10pt,a4paper]{article}
\usepackage[demo]{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}%
    \centering
    \subfloat[label 1]{{\includegraphics[width=5cm]{img1} }}%
    \qquad
    \subfloat[label 2]{{\includegraphics[width=5cm]{img2} }}%
    \caption{2 Figures side by side}%
    \label{fig:example}%
\end{figure}
\end{document}
share|improve this answer
1  
you should run texdoc subfig, then you are sure that you'll get the latest version of the documentation. –  Herbert Dec 8 '11 at 15:06
add comment

Since you didn't tell anything about whether these figures are going to be sub-figures or figures with continued numbering, here is an example that uses the floatrow package.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{floatrow}

\begin{document}
  \begin{figure}[!ht]
    \centering
    \begin{floatrow}
      \ffigbox[\FBwidth]{\caption{Dummy figure}\label{fig:dummy-1}}{%
        \rule{1.6in}{0.9in}   % Just a dummy. Replace with your figure.
      }
      \ffigbox[\FBwidth]{\caption{Dummy figure}\label{fig:dummy-2}}{%
        \rule{1.6in}{0.9in}   % Just a dummy. Replace with your figure.
      }
    \end{floatrow}
  \end{figure}
\end{document}

Note that you have to replace the \rule commands with the images you want to include. For details please see the package manual.

share|improve this answer
    
I just make an anchor for this solution. thanks :-) –  xando Mar 10 '12 at 0:13
add comment