# Put a frame around all pages, except one, in a book

I am writing a book and would like to put a red, 5pt thick frame around all pages, except around one page in the middle of the book, which contains a figure that is bigger than the frame.

The frame should be placed 1cm above the upper text margin, 1cm under the bottom margin and 1.5cm from the left and right margins; it should not suround the header or the footer, which both should be just outside the frame.

I am using XeLaTeX, but have not descided if I am going to use the memoir or the KOMA-script class for the book. It might depend on this answer.

• – Claudio Fiandrino Feb 10 '13 at 17:38
• Welcome to TeX.SE. Just a remark: your figure should not exceed the printing area of the page, i.e. the text body + header + footer + margin notes area. – yo' Feb 10 '13 at 17:39
• Please read the related links on the right first. – kiss my armpit Feb 10 '13 at 17:44
• I have looked at other posts, I still can't draw a border that satisfies my specified distance from the text. I tried pgfpages, but it shrinks the text and puts the border outside the header and footer. I think tikz is what I need, but I am not sure how to make a border around all pages with it. – user25750 Feb 10 '13 at 19:52
• @tohecz I want to turn of the frame on one page. The picture is not really bigger than the printing area, I just tried to keep the question as general as possible. – user25750 Feb 10 '13 at 19:57

Here's a self-documented fully working code. You should of course set up your desired headers (fancyhdr package) and page geometry (geometry package). The code strongly relies on package fancyhdr and keeping the center head empty!

\documentclass{article}

\usepackage{fancyhdr,xcolor}

% the head clashes with the box, so we change the page geometry

\makeatletter

\fancyhf{}
% we use center head to place the box in it
\smash{% occupy no vertical space
\raise\dimexpr-\headsep-\textheight-1cm\relax% move down by text heiht + head sep + 1cm so that it sits 1cm below the text
\hbox to 0pt{% start a box occupying zero space
\color{red}% colour
\fboxsep0pt % \fbox should not add any extra spacing
\fboxrule5pt % line width
\hss\fbox{% \hss is infinitely shrinkable space
% phantom rule occupying exactly the right space:
% width of the text + 2*1.5cm
% height of the text + 2*1cm
\phantom{\rule{\dimexpr\textwidth+3cm}{\dimexpr\textheight+2cm\relax}}%
}\hss%
}%
}%
}

\pagestyle{fancy} % use the newly defined style

% new style {nofancy}
\fancypagestyle{nofancy}{
\ps@@fancy % copy the default {fancy} style
}
\makeatother

\usepackage{lipsum}

\begin{document}

\lipsum[1-20]
\thispagestyle{nofancy}
\lipsum[21-40]

\end{document}

• Very grateful for your help! However, this code fails to draw a frame around the first page of a new chapter, which has a special header/footer style. – user25750 Feb 13 '13 at 21:21
• Please edit your question and add a Minimal Working Example. Then I'll be able to modify the solution so that it suits exacttly your situation. – yo' Feb 13 '13 at 22:06

Redefining the current \fbox to use different margins allows to use the simple \fancypage command from the package fancybox

\documentclass[a4paper,DIV9]{scrartcl}
\usepackage{lipsum}
\usepackage{fancybox}
\makeatletter
\long\def\FBox#1{%
\leavevmode
\setbox\@tempboxa\hbox{%
\color@begingroup
\kern15mm{#1}\kern15mm
\color@endgroup}%
\@frameb@x\relax}
\makeatother

\fancypage{\fboxsep=1cm\fboxrule=5pt\FBox}{}

\begin{document}
\lipsum[1-20]
\thisfancypage{}{}% no frame
\lipsum[21-40]
\end{document}

• This method puts all text into a box, which influence the marigins. It might work, but I am afraid the code is too advanced for me. – user25750 Feb 13 '13 at 21:23
• @user25750: it does not influence the margins and it only redefines the current \fbox command, that's all. – user2478 Feb 14 '13 at 8:40

I experimented a bit and found a solution using the background and tikz packages. I still don't understand how the position option works in the background package - I am not sure from where to where it measures. By playing around with the parameters, I found this solution:

\usepackage[contents={},opacity=1,scale=1.5,color=red!100]{background}
\usepackage{ifthen}