How to display side-by-side figures in LaTeX

The other day I tried putting two graphs side-by-side by setting R’s mfrow parameter. That made the graphs look odd because not everything was scaled proportionately. Then someone told me I could use a LaTeX command to place my original graphs side-by-side rather than creating a new image.

The trick is to use the subfigure package. Include the directive usepackage{subfigure} at the top of your file, then use code something like the following.

\begin{figure}
\centering
\mbox{\subfigure{\includegraphics[width=3in]{fig1.pdf}}\quad
\subfigure{\includegraphics[width=3in]{fig2.pdf} }}
\caption{Text pertaining to both graphs ...} \label{fig12}
end{figure}

If you put text in square brackets immediately after the \subfigure command, that text will be a caption for the corresponding sub-figure. For example, the LaTeX code above might be changed to include the following.

...\subfigure[Description of left graph]{\includegraphics...

31 thoughts on “How to display side-by-side figures in LaTeX

  1. awesome tip, john. very helpful.

    i think there is a small bug (one bracket is missing).

    begin{figure}
    centering
    mbox{subfigure{includegraphics[width=3in]{fig1.pdf}
    quad
    subfigure{includegraphics[width=3in]{fig2.pdf} }}}
    caption{Text pertaining to both graphs …}
    label{fig12}
    end{figure}

  2. thanks, but how can i write two different captions for the two figures while i put them side by side?

  3. Thanks. This was way helpfule for me. To get the caption to work for each subfigure do this

    mbox{subfigure[Caption for Subfig1]{includegraphics[width=3in]{contextmodel}}quad
    subfigure[Caption for Subfig2]{includegraphics[width=3.5in]{contextmodel2}}}

  4. Thx John,
    this is great, since it does work with Sweave. I had some serious trouble to get minipage to work with Sweave (see here) . Btw if you don’t use Sweave, minipage is also a nice way to place graphs or tables next to each other. You can also use seperate captions then.

  5. Thanks for the post, worked great. I like to use a percentage of the text width as opposed to an absolute width in case I change the layout of the page.

    Example:
    begin{figure}
    centering
    mbox{
    subfigure[]{
    includegraphics[width=.5textwidth]{figures/fig-1.eps}
    label{fig-1}
    }quad
    subfigure[]{
    includegraphics[width=.5textwidth]{figures/fig-2.eps}
    label{fig-2}
    }
    }
    centering
    caption{Text pertaining to both graphs …}
    label{fig-all}
    end{figure}

  6. Very nice, but if you want two real figures side by side, you can also write something like this:


    begin{figure}[h]
    centering
    begin{minipage}{.4textwidth}
    includegraphics[width=textwidth]{qrcode}
    caption{Lorem}
    end{minipage}
    begin{minipage}{.4textwidth}
    includegraphics[width=textwidth]{qrcode}
    caption{Ipsum}
    end{minipage}
    end{figure}

  7. thanks, it has helped me
    but i am stucked because it is giving errors when using with hyperref

  8. Salut à tous, j’ai fini mn rapport de stage mais on me demande metre le numero de mon rapport sur la 1ere page et à gauche. J’ai tout fais mais je n’arrive pas à le metre à gauche. Aidez-moi.

    [English translation via Google: Hi all, I ended mn placement report but wonder meter the number of my report on the first page and left. I do everything but I can not seem to meter on the left. Please help me.]

  9. Ibra translation from french,

    Hello to all,

    I have finished my training report but I was asked to write my report number on the left of the first page. I did everything but I am not able to write it on the left.
    Can you help please

  10. I believe it is also possible to put two figures side by side by defining two columns

  11. John,

    as you may have noticed from the amount of “thanks” comments, any article explaining succintly how to do something in LaTeX (that gets Google’s first page) is a lifesaver for thousands as me. I guess many (as me!) didn’t think it was a worthy “just-in-case” skill, and when faced with the need to use it have to default to “just-in-time”, copy-pasting commands until it works.

    Anyway, thanks as well, and keep posting drops of LaTeX hacking/wisdom.

Comments are closed.