5

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?

2 Answers2

5

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}
Gonzalo Medina
  • 505,128
4

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