Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I change the background color only for the current page? I found that I can change the color with \pagecolor{color} but that unfortunately changes the color for all pages after this command. Any ideas how to limit this command only to the current page?

share|improve this question

3 Answers 3

up vote 17 down vote accepted

You could use the \afterpage command from the afterpage package to change the color back.

Here's an example:

\documentclass{article}
\usepackage{lipsum}% for auto generating text
\usepackage{afterpage}
\usepackage{xcolor}
\begin{document}
\lipsum[1-12]
\pagecolor{yellow}\afterpage{\nopagecolor}
\lipsum[22-30]
\end{document}
share|improve this answer
    
Thanks, didn't know what one. –  frabjous Aug 8 '11 at 4:06
3  
@Lev: \nopagecolor is only available for pdfTeX and LuaTeX. However, dvips, dvipdfm(x) and XeTeX do not support it. So I don't think it is very good. –  Leo Liu Aug 8 '11 at 5:35
1  
+1 for afterpage! (for real now, upvote did not work yesterday?!) –  Stephen Mar 13 '12 at 19:17
    
@Leo Liu: I have found that loading \usepackage[pagecolor=none]{pagecolor} and invoking with \newpagecolor{yellow}\afterpage{\restorepagecolor} works with both xelatex and lualatex. –  chandra Mar 25 '12 at 9:02
    
@Leo Liu: Oops! Looks like xelatex issued a warning but gave expected results. xelatex still appears to be unsupported by the package. –  chandra Mar 25 '12 at 11:16

To circumvent the issue of \nopagecolor being only available for pdfTeX and LuaTeX, you could use the pagecolor package and \newpagecolor{yellow} to set the new page color and \restorepagecolor to restore the pagecolor to the one it was before \newpagecolor{yellow} was used. If that color was white, it is white again, if it was none, it is none again, and if it was e.g. green, it is green again. To make the switch back to the old page colour automatically, \afterpage as suggested by frabjous can be used.

\documentclass{article}
\usepackage{lipsum}% for auto generating text
\usepackage{afterpage}% for "\afterpage"
\usepackage{xcolor}
\usepackage{pagecolor}% With option pagecolor={somecolor or none}
% you can set a page colour here.
% "none" is the default, but if \nopagecolor is not available, "white" will be used.
\begin{document}
\lipsum[1-12]
\newpagecolor{yellow}\afterpage{\restorepagecolor}
\lipsum[22-30]
\end{document}
share|improve this answer

Another option is to just use \pagecolor{yellow} followed by \newpage followed by another \pagecolor{white} (or whatever color you want).

\documentclass{article}
\usepackage{lipsum}% for auto generating text
\usepackage{xcolor}
\begin{document}
\lipsum[1-12]
\pagecolor{yellow}
\newpage
\pagecolor{white}
\lipsum[22-30]
\end{document}
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.