# LaTeX inserts blank page between figures

I am writing a relatively long text in LaTeX. At some points I need to include a bunch of large figers (2 figures per page, no text) using \figure and \includegraphics. In order to avoid pages with only one figure, I use [H] / [P] placement specifier. The problem is that LaTeX for some reason puts a blank page between the pages with figures.

I end up with something like: text page - page with 2 figures - blank page - page with 2 figures.

-
TeX will create an empty page if the image does not fit on the current page to be shipped. Try explicitly to set the height and width of the images. Keep downsizing until the pages are as expected. –  zeroth Jan 3 '12 at 12:49
add comment

## 2 Answers

You didn't provide a minimal example, so it's hard to say what exactly is going on. However, if you simply want "to avoid pages with only one figure", put the two \includegraphics macros inside one figure environment (and add some vertical space with \vspace{floatsep}).

EDIT: Contrary to Mico's assertion, it is possible to create separate cross-references to the graphics inside figure -- see my updated example.

\documentclass{article}

\usepackage{lipsum}

\begin{document}

\lipsum[1]

A cross-reference to figures~\ref{first}  and~\ref{second}.

\begin{figure}
\centering

\rule{1cm}{8cm}% placeholder for graphics
\caption{First}\label{first}

\vspace{\floatsep}

\rule{1cm}{8cm}% placeholder for graphics
\caption{Second}\label{second}
\end{figure}

\end{document}

-
It's possible to get \ref to work and generate separate (correct) cross-references with your method, but it doesn't seem to work at all if the hyperref package is loaded as well. I'm editing my answer to clarify this aspect of the cross-referencing process. –  Mico Jan 3 '12 at 16:29
Thanks for clarifying what works and what doesn't! –  lockstep Jan 3 '12 at 16:31
add comment

If you're sure that two floats (including their captions) fit on a page, you can use the following method -- see also this question and the associated answers -- to force LaTeX to place the floats on a single page. By creating two separate figure floats (one per image) rather than one float that contains two images and two captions (and any associated labels for cross-referencing purposes), one preserves compatibility of one's code with the hyperref package. If you don't use hyperref at the moment, and if you don't foresee a need to use hyperref in the future, the simpler approach provided in @lockstep's answer will do too.

The example code below employs the command \afterpage of the afterpage package. It also uses dummy images (black squares, really) as placeholders for the real graphics (which one would load, most likely, with the \includegraphics command). The example also loads the lipsum package to provide filler text. Finally, the hyperref package is loaded as well, to demonstrate that the approach is compatible with hyperref. (Be sure to compile the program twice to let LaTeX resolve the cross-references.)

\documentclass{article}
\usepackage{afterpage,lipsum,hyperref,graphicx}
\begin{document}

First, some cross-references to Figures \ref{fig:first} and \ref{fig:second}.

\section{Some random thoughts}

\afterpage{
\clearpage   % This \clearpage instruction serves to relax temporarily some
% of LaTeX's restrictions on how floats may be placed.

\begin{figure}[t]
\caption{First figure} \label{fig:first}
\centering
\rule{1in}{1in} % dummy image
%\includegraphics{fig1}  % insert real file name
\end{figure}

\begin{figure}[h]
\caption{Second figure} \label{fig:second}
\centering
\rule{1in}{1in} % dummy image
%\includegraphics{fig2} % insert real file name
\end{figure}

\clearpage % This second \clearpage instruction forces LaTeX to typeset both
% accumulated floats
} % end of \afterpage{} group
\lipsum[1-8]

\end{document}


If you have more than one page that should contain two floats per page, you needn't start a new afterpage group every time. Instead, after the second \clearpage instruction, you'd just provide the code to typeset two more figures, followed by a \clearpage instruction; and so on until all figures of this type have been placed.

If you find that LaTeX can't place both floats on one page, you may want to experiment with reducing the value of the length parameter \floatsep (default value for a document whose main font size is 10pt: "12pt plus 2pt minus 2pt"). For instance, you might issue the command

\setlength\floatsep{0.5\baselineskip plus 1pt minus 2pt}


in the preamble.

-
add comment