265

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.

1
  • @Matthew-leingang answer works for beamer presentations too Feb 9, 2020 at 7:41

4 Answers 4

283

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}

sample code rendering

I was surprised to discover two \captions in the same figure environment actually work as desired.

HT: LaTeX Matters via Google

20
  • 2
    This 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". Nov 23, 2010 at 9:09
  • 11
    I normally put a \hfill between the minipages to spread them evenly over the text width. Apr 28, 2011 at 17:49
  • 2
    This worked nicely, but then I wanted another line of pictures underneath. Is that possible somehow? Sep 19, 2013 at 18:31
  • 5
    What 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 3, 2017 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. Dec 4, 2017 at 16:18
29

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.

1
  • 1
    do you have actual code or an example to be used? Oct 25, 2016 at 21:03
26

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}

enter image description here

2
  • 3
    Is floatrow still actively maintained?
    – muk.li
    Jul 10, 2015 at 11:09
  • I don't think so, but I'm not sure. Last change dates back to July 2012.
    – Bernard
    Jul 10, 2015 at 11:15
14

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.

4
  • 1
    Since you're already operating in a figure environment, 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, 2014 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, 2014 at 17:26
  • I don't get the error message about "Caption(s) lost" when replacing \captionof with \caption. I expanded your code snippet into an MWE by loading the graphicx and caption packages; are you maybe loading additional packages that could create some interference?
    – Mico
    Feb 16, 2014 at 18:01
  • why do I get an error die to \captionofnsays undefined control sequence... :/ Oct 25, 2016 at 21:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .