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.

I use the geometry package to define paper size and text area of a (one page) document:

\usepackage[
  paperwidth=420mm,
  paperheight=297mm,
  text={365mm,270mm},
  centering
]{geometry}

I wish to color the background of the specified text area. I use this.

\usepackage{color}
\pagecolor{magenta}

This, however, colors the whole paper (420*297 mm2), rather than just the text area (365*270 mm2).

How do I color only the text area?

share|improve this question
add comment

2 Answers

You can use the tikzpagenodes package:

\documentclass{article}
\usepackage{tikzpagenodes}
\usepackage{lipsum}
\usepackage{showframe}

\newcommand\ColorTextArea{%
\begin{tikzpicture}[remember picture,overlay]
\fill[cyan!20] 
  (current page text area.north west) rectangle (current page text area.south east);
\end{tikzpicture}%
}
\begin{document}
\ColorTextArea
\lipsum[1-3]

\end{document}

enter image description here

The showframe package was only used to have some frames for the page layout to help visualization.

\ColorTextArea only affects the page in which it was invoked. If you want the effect for all the pages, use the atbegshi package:

\documentclass{article}
\usepackage{tikzpagenodes}
\usepackage{lipsum}
\usepackage{atbegshi}
\usepackage{showframe}

\newcommand\ColorTextArea{%
\begin{tikzpicture}[remember picture,overlay]
\fill[cyan!20] 
  (current page text area.north west) rectangle (current page text area.south east);
\end{tikzpicture}%
}

\AtBeginShipout{\ColorTextArea}
\AtBeginShipoutFirst{\ColorTextArea}

\begin{document}
\lipsum[1-40]

\end{document}
share|improve this answer
add comment

This way it is automatically done every page.

\documentclass{article}
\usepackage{everypage}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{calc}
\AddEverypageHook{\color{blue!20}\smash{\hspace{\oddsidemargin}%
  \rule[-\textheight-\headsep-\headheight-\topmargin]{\textwidth}{\textheight}}}
\begin{document}
\lipsum[1-7]
\end{document}

Thanks to "Killmargins" package? for the images of text measures.

enter image description here

share|improve this answer
add comment

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.