How can I put two figures side-by-side? Not two sub-figures, but two actual figures with separate "Fig.: bla bla" captions. A figure is supposed to spread over the entire text width, but I have two figures which are narrow and long, and I need to save the space in order to withstand the pages limit.
-
@Matthew-leingang answer works for beamer presentations too – Tejas Shetty Feb 09 '20 at 07:41
4 Answers
You can put minipages inside a figure environment and get separate captions for each of them.
\documentclass{article}
\usepackage{lipsum}
\usepackage{mwe}
\begin{document}
How can I put two figures side-by-side? Not two sub-figures, but two actual figures
with separate "Fig.: bla bla" captions. A figure is supposed to spread over the
entire text width, but I have two figures which are narrow and long, and I need to
save the space in order to withstand the pages limit.
\lipsum
\begin{figure}
\centering
\begin{minipage}{0.45\textwidth}
\centering
\includegraphics[width=0.9\textwidth]{example-image-a} % first figure itself
\caption{first figure}
\end{minipage}\hfill
\begin{minipage}{0.45\textwidth}
\centering
\includegraphics[width=0.9\textwidth]{example-image-b} % second figure itself
\caption{second figure}
\end{minipage}
\end{figure}
\lipsum[3]
\end{document}
I was surprised to discover two \captions in the same figure environment actually work as desired.
HT: LaTeX Matters via Google
- 44,937
- 14
- 131
- 195
-
2This is what I ended up with. It appears that the actual semantics of figure is: "Everything with a caption in this environment is a figure, and it all floats together". – Little Bobby Tables Nov 23 '10 at 09:09
-
11I normally put a
\hfillbetween theminipages to spread them evenly over the text width. – Martin Scharrer Apr 28 '11 at 17:49 -
2This worked nicely, but then I wanted another line of pictures underneath. Is that possible somehow? – Thomas Ahle Sep 19 '13 at 18:31
-
1I'm confused. Why don't you have the command
\includegraphics[width=0.9\textwidth]{image.pdf}anywhere? – Charlie Parker Oct 25 '16 at 21:09 -
1@CharlieParker: I wrote and used the
\exedoutmacro to draw a black box for a sample image. Otherwise the example code won't comple without an image.pdf to go with it. Now we have themwepackage to provide sample placeholder images. – Matthew Leingang Oct 26 '16 at 00:38 -
1@CharlieParker: I went ahead and updated the answer using the
mwepackage and placeholder images. I hope that's less confusing. – Matthew Leingang Oct 26 '16 at 00:44 -
1sorry for being annoying, is it ok if you insert an image of what I'm supposed to see? (though thanks so far) – Charlie Parker Oct 31 '16 at 23:38
-
1
-
1Note that you mustn't have an empty line between the minipages or you won't end up with the two columns. – jsaven Aug 20 '17 at 05:08
-
1@jsaven: You're absolutely right. An empty line introduces a
\partoken which creates a new paragraph. – Matthew Leingang Aug 22 '17 at 17:13 -
5What if the images [A] and [B] are not the same height? Could you extend your answer to show how to vertically align the two captions? – gen Dec 03 '17 at 15:08
-
6@gen: Just use the
[b]optional argument after each of the\begin{minipage}commands. That aligns the two at their bottom edges. – Matthew Leingang Dec 04 '17 at 16:18 -
@MatthewLeingang Thanks! However, I found that to be
[t]rather than[b]. Otherwise the captions and not the figures of different height themselves will be aligned. – tommy.carstensen Feb 23 '18 at 10:24 -
@MatthewLeingang: is it possible to label them as subfigures, i.e. the main figure if Figure 5, the minipage objects are Figure 5a and 5b? – Alex Dec 12 '19 at 20:52
-
1@Alex: If that's what you want, you should look at
subcaption. – Matthew Leingang Dec 12 '19 at 23:54 -
I am using the same code in the IEEE conference format in overleaf. But my figures overwrite the text. Am I missing something here? can anyone please help and identify where I am making a mistake. – Sohaib Bin Altaf Sep 24 '20 at 18:46
-
1@SchaibBinAitaf you should probably create a new question with your code worked down to a minimal working version. Link to it from here if you like. – Matthew Leingang Sep 24 '20 at 19:58
-
i have applied your code but along with the images, strange text has appeared in my doc. was it because of 'lipsum' pehaps? – sato Aug 09 '21 at 07:41
-
and the figures are at the top of the page rather than after a certain portion of text. how do i move the images? – sato Aug 09 '21 at 07:46
-
Since your figures shall be side by side, they are not expected to float independently. So you need just one figure environment for both objects.
Within this figure environment, you may use minipages (like Matthew already suggested). Some additions:
- minipages understand optional alignment parameters to align at top, bottom or center.
- For adding a caption to the minipages, I recommend to use the subcaption package. It is part of the feature-rich caption package.
Nevertheless you could check out the subfig package. That task could be handled like subfigures even if you customize the captions such that they look like two independent figures.
- 231,401
The floatrowpackage can easily do that (and many other things) with its floatrow environment:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{floatrow}%
\begin{document}
\begin{figure}[!h]
\begin{floatrow}
\ffigbox{\includegraphics[scale = 0.8]{casxinf1}}{\caption{Case $ x < 1 $}\label{case1}}
\ffigbox{\includegraphics[scale = 0.8]{zoom}}{\caption{A zoom}\label{zoom}}
\end{floatrow}
\end{figure}
\end{document}

- 271,350
-
3
-
I don't think so, but I'm not sure. Last change dates back to July 2012. – Bernard Jul 10 '15 at 11:15
I got this working in a document with two text columns, just wanted to share what I did.
In this case, I wanted one figure of two side-by-side images to appear within one text column.
The \centering inside the minipages caused trouble so I removed them. Moreover, \linewidth (one-column width) needs to be used rather than \textwidth (which equals the full two-column width).
Another pitfall is the width= parameter of the \includegraphics: Since we're within a minipage, this width refers to the width of the minipage, not the width of the column.
Here's my code:
\begin{figure}
\centering
\begin{minipage}{.45\linewidth}
\includegraphics[width=\linewidth]{img1.png}
\captionof{figure}{First caption}
\label{img1}
\end{minipage}
\hspace{.05\linewidth}
\begin{minipage}{.45\linewidth}
\includegraphics[width=\linewidth]{img2.png}
\captionof{figure}{Second caption}
\label{img2}
\end{minipage}
\end{figure}
The \hspace{.05\linewidth} makes sure there is some horizontal space between the two captions.
- 243
-
1Since you're already operating in a
figureenvironment, what is the advantage of using\captionof{figure}{...}instead of the simpler\figure{...}? Second, I'm confused by your write-up: you state that you're looking to have two figures within one column -- presumably one above the other, right? -- yet the code you post would place them side-by-side. Third, please don't post just code snippets, but compilable examples that start with\document{<some class>}and end with\end{document}. – Mico Feb 16 '14 at 16:27 -
@mico I tried replacing with
\figure{...}, but that gives me a "Caption(s) lost" error. I do wish side-by-side images, but within one text column, e.i., not spanning both text colums. I've clarified that now, it was mis-leading before, thanks for pointing it out. – Carl Feb 16 '14 at 17:26 -
I don't get the error message about "Caption(s) lost" when replacing
\captionofwith\caption. I expanded your code snippet into an MWE by loading thegraphicxandcaptionpackages; are you maybe loading additional packages that could create some interference? – Mico Feb 16 '14 at 18:01 -
why do I get an error die to
\captionofnsays undefined control sequence... :/ – Charlie Parker Oct 25 '16 at 21:44
