# Change the page color starting at page x

I need to be able to change the background color of a document and the pagecolor package seems like a good fit. However, what I also need is a command that allows me to color all pages that start at a certain page number (think about highlighting a document's pages that are over the official page limit of N pages). It is probably a simple newcommand two-liner, but I don't get it. Does anyone know?

You could load the atbegshi package and use that package's \AtBeginShipout macro to switch on page coloring from a certain page onwards.

\documentclass{article}
\usepackage{pagecolor}
\usepackage{atbegshi} % for '\AtBeginShipout' macro
% Make page color "light red" *after* page 2
\AtBeginShipout{\ifnum\value{page}=2\pagecolor{red!20}\fi}
\usepackage{lipsum}
\begin{document}
\lipsum[1-20] % filler text
\end{document}

• Thank you! That works perfectly. I have never heard of the atbegshi package before! – Erdbeere Feb 24 '16 at 13:44

Based on my answer at What are the ways to position things absolutely on the page?, but using \AddEverypageHook instead of \AddThispageHook to place a full-page \rule in the background of the page.

\documentclass{article}
\usepackage{everypage}
\usepackage{xcolor}
\usepackage{lipsum}
% THESE ARE LaTeX DEFAULTS; CAN CHANGE IF NEEDED.
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
\newcommand\ateveryxy[3]{%
\raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{#3}}}}
% VERIFIED THAT SETTING \hoffset AND \voffset DO NOT BREAK SOLUTION.
%\hoffset=0.4in
%\voffset=0.2in
\def\BGcolor{red!10}
\begin{document}
\lipsum[1-17]
% COMMENCE COLORED PAGES HERE
\ateveryxy{0in}{\paperheight}{\textcolor{\BGcolor}{\rule{\paperwidth}{\paperheight}}}
\lipsum[17-29]
\def\BGcolor{blue!10}% CHANGE THE COLOR HERE
\lipsum[30-34]
\end{document}

• Thank you as well. I got it working, though the previous answer is much shorter, I will stick with it. – Erdbeere Feb 24 '16 at 13:45

The following suggestion does make sense only if you already use scrlayer-scrpage as package for header and footer. Then you can define a new background layer and add this to all layer page styles including empty.

\documentclass{article}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{scrlayer-scrpage}
\DeclareNewLayer[
background,
contents={\ifnum\value{page}>3\color{orange!20}\rule{\layerwidth}{\layerheight}\fi}
]{pagecolor}

\begin{document}
\Blinddocument
\end{document}


Or you could use option onpsinit

\documentclass{article}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{scrlayer-scrpage}
\KOMAoptions{onpsinit={\ifnum\value{page}=3\pagecolor{orange!10}\fi}}
\begin{document}
\Blinddocument
\end{document}


In both cases the colored background starts on page 4.