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...
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}
Thanks for the tip! It works flawlessly. Smiling! :) Smiling!
Just what I needed. Thanks!
thanks for this post. very useful.
thanks, but how can i write two different captions for the two figures while i put them side by side?
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}}}
Many thanks. Very useful. I need it.
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.
The subfigure package is outdated, subfig should be used instead (according to subfigures page on CTAN).
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}
Thanks for this tip. It helped me!
Thanks!!!! It worked!!
Very useful. Thanks for posting this.
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}
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.
Awesome tip. Worked like a charm.
Cheers
Thanks, it works fine. (I am using it in Springer One Column Documents).
mbox worked like a charm :)
thanks, it has helped me
but i am stucked because it is giving errors when using with hyperref
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.]
Thanks a lot!
This post helped me.
Thanks alot. Now I can include figures in my tex files.
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
Very thanq :). Want to correct Andi and Matt. The width is not 0.4textwidth , but it is 0.4linewidth
Thanks its helpful!!
I believe it is also possible to put two figures side by side by defining two columns
Hi!
The subfigure package is not maintained. I’d recommend using either the subcaption or the subfig package.
Thank’s for the help.
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.
Thanks. It is great. Save me a lot of time.
Thank you! Saved the day.
It works flawlessly. Thanks a lot for the help!!
As in 2010 and 2012, the subfigure package is still obsolete. Please add a note to the original post that the given infomation is not up to date.
How can I control the width and basically the font size of the caption?