How to display side-by-side figures in LaTeX

by John on January 14, 2009

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...

{ 23 comments… read them below or add one }

1

jerry 02.26.09 at 13:08

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

Michael 04.28.09 at 10:04

Thanks for the tip! It works flawlessly. Smiling! :) Smiling!

3

Steve 10.09.09 at 07:22

Just what I needed. Thanks!

4

kerimcan 11.19.09 at 15:05

thanks for this post. very useful.

5

mahyar 03.02.10 at 03:27

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

6

Claudine Allen 06.24.10 at 09:58

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}}}

7

Alexandra 07.22.10 at 10:41

Many thanks. Very useful. I need it.

8

ran2 08.03.10 at 16:30

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.

9

Torbjorn 11.18.10 at 17:28

The subfigure package is outdated, subfig should be used instead (according to subfigures page on CTAN).

10

Matt Pillar 12.02.10 at 16:14

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=.5\textwidth]{figures/fig-1.eps}
\label{fig-1}
}\quad
\subfigure[]{
\includegraphics[width=.5\textwidth]{figures/fig-2.eps}
\label{fig-2}
}
}
\centering
\caption{Text pertaining to both graphs …}
\label{fig-all}
\end{figure}

11

Elmano 12.13.10 at 08:56

Thanks for this tip. It helped me!

12

suvam 06.06.11 at 16:20

Thanks!!!! It worked!!

13

Jayaram Sethuraman 06.15.11 at 14:21

Very useful. Thanks for posting this.

14

Andi Hasenkopf 07.21.11 at 10:46

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}{.4\textwidth}
\includegraphics[width=\textwidth]{qrcode}
\caption{Lorem}
\end{minipage}
\begin{minipage}{.4\textwidth}
\includegraphics[width=\textwidth]{qrcode}
\caption{Ipsum}
\end{minipage}
\end{figure}

15

Wojtek Myszka 07.21.11 at 11:17

There is also package called floatrow. Not anly allows placing various floats side-by-side but also adds great functionality to manage captions. With extensive documentation.

16

Bogdan 08.29.11 at 07:09

Awesome tip. Worked like a charm.

Cheers

17

Muhammad Azeem Abbas 10.31.11 at 06:12

Thanks, it works fine. (I am using it in Springer One Column Documents).

18

cmdline 12.15.11 at 22:28

\mbox worked like a charm :)

19

prateek 12.16.11 at 03:50

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

20

Ibra 01.09.12 at 10:17

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.]

21

Abhiram Soori 01.12.12 at 00:28

Thanks a lot!
This post helped me.

22

Iftikhar Ali 01.20.12 at 09:36

Thanks alot. Now I can include figures in my tex files.

23

Human_translation. 01.25.12 at 15:17

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

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>