33

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?

karlkoeller
  • 124,410
Chogg
  • 964

2 Answers2

43

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

Werner
  • 603,163
7

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?

Fran
  • 80,769