0

I'm looking for a way to change the page color of a float page. I'm using the [p] placement for the respective figure. Consider the following MWE:

\documentclass{scrbook}
\usepackage{afterpage}
\usepackage{pagecolor}

\begin{document}
Text on a clean page. %The page is white by default.
\clearpage
Text before figure. %This page is red already.
\begin{figure}[p]
    \pagecolor{red}\afterpage{\pagecolor{none}}
    Figure text.
\end{figure}
Text after figure.
\clearpage %The float is placed, \afterpage kicks in and restores the page background
Again, text on a clean page.
\end{document}

The \pagecolor command is carried out as soon as the float is reached in the source, so all the pages up to the float are already red. This question kind of deals with the same problem, however its solution hooks to any float page shipped out. I only want the colored background for certain float pages, not all of them. How can I change the page color for only a certain float page?

(Given the referenced question and solution, I was thinking of adding a conditional that must be set for \AddToShipoutPictureBG to change the background, which I could set when I want a colored float page. But it seems inelegant and just too hacky...)

0

1 Answer 1

1

Looking at the floatpag package, I figured you could use the same trick for pagecolor. I had to create my on \thispagecolor command.

\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{floatpag}

\makeatletter
\newcommand{\@thispagecolor}{none}
\let\@pagecolornone=\@thispagecolor
\newcommand{\thispagecolor}[1]{\gdef\@thispagecolor{#1}}

\AddToHook{shipout/background}{\ifx\@thispagecolor\@pagecolornone\relax
  %\put(1in,-1in) {color=none}%
\else
  \put(0pt,-\paperheight) {\textcolor{\@thispagecolor}{\rule{\paperwidth}{\paperheight}}}%
  \global\let\@thispagecolor=\@pagecolornone
\fi}
  
\newcommand{\floatpagecolor}[1]{\gdef\at@float@page{\thispagecolor{#1}}}
\makeatother

\floatpagecolor{red}

\begin{document}
Text on a clean page. %The page is white by default.
\clearpage
Text before figure. %This page is red already.
\begin{figure}[p]
    Figure text.
\end{figure}
Text after figure.
\clearpage %The float is placed, \afterpage kicks in and restores the page background
Again, text on a clean page.
\end{document}

You must log in to answer this question.

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