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 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.

share|improve this question
    
Welcome to TeX.SX. –  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. –  tohecz Feb 10 '13 at 17:39
    
Please read the related links on the right first. –  Fifa Earth Cup 2014 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
show 2 more comments

3 Answers

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
\usepackage[headsep=1.3cm,headheight=4cm]{geometry}
\renewcommand{\headrulewidth}{0pt}

\makeatletter

\fancyhf{}
% we use center head to place the box in it
\fancyhead[C]{\leavevmode
  \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%
    }%
  }%
}

\fancyhead[R]{\thepage} % print the page number in the right head

\pagestyle{fancy} % use the newly defined style

% new style {nofancy}
\fancypagestyle{nofancy}{
  \ps@@fancy % copy the default {fancy} style
  \fancyhead[C]{} % make the center head empty
}
\makeatother

\usepackage{lipsum}

\begin{document}

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

\end{document}
share|improve this answer
    
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. –  tohecz Feb 13 '13 at 22:06
add comment

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}
share|improve this answer
1  
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. –  Herbert Feb 14 '13 at 8:40
add comment

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}
\AddEverypageHook{%
\ifthenelse{\isodd{\thepage}}%
{\backgroundsetup{angle=0,position={2.6cm,-4.7cm},%
contents={\begin{tikzpicture}
\draw [ultra thick] (0,0) rectangle (0.75\textwidth,0.73\textheight);
\end{tikzpicture}}}}%
{\backgroundsetup{angle=0,position={3.85cm,-4.7cm},%
contents={\begin{tikzpicture}
\draw [ultra thick] rectangle (0.75\textwidth,0.73\textheight);
\end{tikzpicture}}}}%
\BgMaterial}

It still remains to work out how to turn off the background when not needed.

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.