# Set page color for double-double float

I have a custom command, comprising two instances of \@dblfloat. I'd like to change the page color on pages where this occurs. I can do this for a single instance of \@dblfloat, but not more.

In the following example, the first figure is coloured blue (correctly) but the subsequent figures are not. If I place \pagecolor without \afterpage before \@dblfloat, the page preceding the floats is also coloured.

(Note that in this example, I'm using a figure float to provide an MWE, but I'd like a solution for all floats -- including custom ones.)

\documentclass[twocolumn]{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{afterpage}

\makeatletter
\newenvironment{dblfigure}{
\afterpage{\pagecolor{blue!50}}
\@dblfloat{figure}
}{
\afterpage{\clearpage\nopagecolor}
\end@dblfloat

}

\newcommand{\dblpagefigure}[2]{

\@dblfloat{figure}
% \pagecolor{blue!50} puts color too early
#1
\end@dblfloat
\@dblfloat{figure}
#2
\end@dblfloat
}
\makeatother

\usepackage{lipsum}

\begin{document}

\lipsum[1-4]
\begin{dblfigure}
\caption{Some other figure}
\includegraphics{example-image}
\end{dblfigure}

\lipsum
Some text to avoid \lipsum taking up an exact page.

\lipsum

\dblpagefigure{
\caption{Some figure}
\includegraphics[width=\textwidth]{example-image}
}{
\caption{Another figure}
\includegraphics[width=\textwidth]{example-image}
\afterpage{\clearpage\nopagecolor}
}

\lipsum
\lipsum

\end{document}

• It doesn't turn blue when I test it – caverac Feb 10 '18 at 11:50
• I am sorry, but still it doesn't – caverac Feb 10 '18 at 12:12
• Hmmm, sorry this is causing difficulty, but on my machine when the line on line 19 is not commented out, I get page 6 and 7 colored blue, which is what I want, but also I get page 6 colored blue, which I don't. With the line commented out, pages 5-7 are not colored. – Hugh Feb 10 '18 at 12:17

Probably the previous page to the figures are also colored because of the way floats work in latex. See for instance the green page, it doesn't have that problem

\documentclass[twocolumn]{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{afterpage}

\makeatletter
\newenvironment{dblfigure}{
\pagecolor{blue!50}\afterpage{\nopagecolor}
\@dblfloat{figure}
} {
\end@dblfloat
}

\newenvironment{sglfigure}{
\pagecolor{green!50}\afterpage{\nopagecolor}
\begin{figure}
} {
\end{figure}
}

\newcommand{\dblpagefigure}[2]{

\begin{dblfigure}
#1
\end{dblfigure}
%
\begin{dblfigure}
#2
\end{dblfigure}
}
\makeatother

\usepackage{lipsum}

\begin{document}

\lipsum[1-4]

\begin{dblfigure}
\caption{Some other figure}
\includegraphics{example-image}
\end{dblfigure}

\lipsum
Some text to avoid \lipsum taking up an exact page.

\lipsum

\dblpagefigure{
\caption{Some figure}
\includegraphics[width=\textwidth]{example-image}
}{
\caption{Another figure}
\includegraphics[width=\textwidth]{example-image}
}

\lipsum
\lipsum

\lipsum[1]
\begin{sglfigure}
\caption{Some other figure}
\includegraphics[width = 0.5\textwidth]{example-image}
\end{sglfigure}

\lipsum

\end{document}