1

It seems that using \pagecolor after \newpage affects pages before \newpage in some cases, e.g. floating figures.

Here is a minimal example:

\documentclass{scrreprt}
\usepackage{graphicx}
\usepackage{blindtext}
\usepackage{xcolor}
\newcommand{\normalpagestyle}{
  \newpage
  \pagecolor{white}
  \color{black}
  \addtokomafont{chapter}{\color{red}\fontsize{16}{16}\selectfont}
}
\newcommand{\specialpagestyle}{
  \newpage
  \pagecolor{red}
  \color{white}
  \addtokomafont{chapter}{\color{white}\fontsize{16}{16}\selectfont}
}
\begin{document}
\normalpagestyle
\chapter{Test}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\specialpagestyle
\blinddocument

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}
\normalpagestyle
\blinddocument
\end{document}

Is there any way to work around this behaviour?

  • 1
    Have you tried \clearpage instead of \newpage? – user31729 Nov 15 '17 at 13:25
  • just tried it, \clearpage leads to the same result – Klaus Stadler Nov 15 '17 at 13:27
  • sorry, previewed the wrong file after compiling - it actually works – Klaus Stadler Nov 15 '17 at 13:45
2

For me replacing both instances of \newpage with \clearpage seems to work:

\documentclass{scrreprt}
\usepackage{graphicx}
\usepackage{blindtext}
\usepackage{xcolor}
\newcommand{\normalpagestyle}{
  \clearpage
  \pagecolor{white}
  \color{black}
  \addtokomafont{chapter}{\color{red}\fontsize{16}{16}\selectfont}
}
\newcommand{\specialpagestyle}{
  \clearpage
  \pagecolor{red}
  \color{white}
  \addtokomafont{chapter}{\color{white}\fontsize{16}{16}\selectfont}
}
\begin{document}
\normalpagestyle
\chapter{Test}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\specialpagestyle
\blinddocument

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}

\begin{figure}[ht]
  \centering
  \rule{10cm}{10cm}
\end{figure}
\normalpagestyle
\blinddocument
\end{document}
3

Skillmon has already said how to fix the issue, but to explain what is happening, \pagecolor does not affect earlier pages, rather the figures are being inserted after the page colour has changed.

You have [ht] so the floats are not allowed on a float page they are only allowed on pages that also contain text. As you have no text they are all being stacked in the queue waiting to have some pages on which they may be placed.

The \specialpagestye then changes the page colour to red, but still not floats have been inserted into the document.

Then finally the \chapter issues a \clearpage, unlike \newpage \clearpage flushes all floats as an emergency operation effectively forcing p into their optional placement and ignoring all constraints. So all the floats up to that point are then output (but the page is already red).

In older latex releases if you stacked up floats in this way you would get an error if you used more than 18 "no room for a new float" but recent releases use etex extended registers and so you can stack up several thousand floats without hitting that error.

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.