TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
    
Welcome to TeX.SE! – Mico Feb 24 at 13:26
up vote 5 down vote accepted

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}
share|improve this answer
    
Thank you! That works perfectly. I have never heard of the atbegshi package before! – Erdbeere Feb 24 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]{%
 \AddEverypageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}%
  \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}
share|improve this answer
    
Thank you as well. I got it working, though the previous answer is much shorter, I will stick with it. – Erdbeere Feb 24 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}
\AddLayersAtBeginOfPageStyle{@everystyle@}{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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.