28

I have two images that I would like to appear on the same page. Each figure should appear as a separate figure with its own caption.

My problem is that LaTeX sometimes places the figures on separate pages.

I currently have achieved this by putting two \psfragfig commands consecutively within the same figure environment. This seems a simple and succesful approach, but I wonder if I am not using the figure environment correctly by doing this. Should I use the subcaption package instead?

2
  • Solved your question this asnwer?
    – Fran
    Sep 19 '13 at 20:05
  • I want to know if having two images in the same figure environment is a problem, which I don't this post quite deals with.
    – Chogg
    Sep 19 '13 at 20:28
39

You are using the figure environment correctly. The environment is merely a floating shell that primarily contains figure-related content. Sure you can put a table inside of it, but most people include an image and some text (in the form of a caption). If you include more than one, it's just the same:

\begin{figure}[ht]
  \centering
  \includegraphics[<options>]{<image1>}
  \caption{<caption1>}

  \vspace*{\floatsep}% https://tex.stackexchange.com/q/26521/5764

  \includegraphics[<options>]{<image2>}
  \caption{<caption2>}
\end{figure}

The gap between consecutive floats is given by \floatsep.

One would only use \subcaption if you have the same main content you want to illustrate, but the two figure resemble slight variations of one another. So, they should fit under/above the same heading (\caption), but each with a sub-numbering (\subcaption).

5
  • +1, nice, simple answer to a problem I had as well. Just curious, is there a reason for using the starred version of vspace?
    – xebtl
    May 17 '15 at 14:10
  • @xebtl: In this case, not really. Here is an example where it would matter: Adding vertical space at the start of a page
    – Werner
    May 17 '15 at 15:03
  • How does it work with the labels then? I need separate figure numbers and separate labels! Jun 4 '20 at 18:12
  • 1
    @JohannesLemonde: Place the \label after the \caption. You'll get separate figure numbers in both and can use separate labels. Try it!
    – Werner
    Jun 4 '20 at 18:13
  • @Werner : So cool! Thank you!! Jun 4 '20 at 18:42
6

To have two figures and two captions in the same float, you only need include two figures and two captions in the float. That is all :). See the MWE.

In case that you want to include also a table in a figure environment (or a figure in a table environment), then you can use the caption package ad the \captionof command.

\documentclass[twocolumn]{article}
\usepackage{graphicx,mwe,caption,lipsum}
\begin{document}
\section{Cheking cross-references}
See figures \ref{a} and \ref{b} on the same float in page \pageref{a}. Figure \ref{c} is on page \pageref{c}. (All is correct).
\section{Dummy text}
\lipsum[1-2] % dummy text
\begin{figure}[t] %float with two figures
\centering
\includegraphics[width=.5\linewidth]{example-image-a}
\caption{Image A\label{a}}\bigskip 
\includegraphics[width=.5\linewidth]{example-image-b}
\caption{Image B\label{b}}
\end{figure}
\lipsum[3-5]
% float in next page
\begin{figure}[b]
\centering
\includegraphics[width=.5\linewidth]{example-image-16x10}
\caption{Image C\label{c}}
\end{figure}
\lipsum[3-10]

\end{document}

MWE

Edit: Spacing with the \vspace*{\floatsep} of Werner's answer it is much more correct than \bigskip.

I case that you want force to figures to stay in the same page but not together (two floats in top and bottom, for example), then you can try to force float position with floats options and/or relaxing floating penalties. Please see:

How to influence the position of float environments like figure and table in LaTeX?

How to use the placement options [t], [h] with figures?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.