What if I want to set a padding around the page body (on all pages), draw a frame/border around it, and then add some margin?

The geometry package doesn't seem to have an option for this among its basic options because it doesn't separate padding and margin.

(I'm asking this question about the whole page body, rather than about a box explicitly coded in the sources.

I'm dealing with LaTeX.)

What I want to achieve -- each page is printed like this:

>outer margin< | >left<  >mpwidth< >text body< >right< | >outer margin<
               |                     ......            |
               |                    Text text          |         
               |         marginpar  Text text          |         
               |                    Text text          |         
               |                     ......            |

Then, I'd also like to change the color of the frame depending on the text (with a command from the text). The frame/border style could be fancier than just a plain rule/line. The piece inside the frame is like a complete customizable page layout: a custom left margin width, a custom right margin width, and a custom marginpar width. This doesn't cross the frame. The frame is at a fixed distance from the edge of the paper ("outer margin").


1 Answer 1


I think the package background in combination with tikzpagenodes is a good choise.

As a starting point you can use:

Add background colour to margin notes area

However there is one disclaimer. The package background can change the color of the frame only for the whole page.

Here an example where you can control the distance between the frame and the text by the new two dimensions \xinnersep and \yinnersep:

 \begin{tikzpicture}[remember picture,overlay]
  \draw[blue,line width=2pt,] ([xshift=-\xinnersep,yshift=\yinnersep]current page text area.north west) --
                                             ([xshift=\xinnersep,yshift=\yinnersep]current page text area.north east) -- 
                                             ([xshift=\xinnersep,yshift=-\yinnersep]current page text area.south east) -- 
                                             ([xshift=-\xinnersep,yshift=-\yinnersep]current page text area.south west) -- cycle;

  • Thanks a lot! This almost works (yshift caused some problem, but I actually don't need it: the whole rectangle appeared below the bottom...) Commented Aug 4, 2013 at 14:08
  • Could you please tell me what the bettrr way woulf be to select a different color in the middle of the document? (For whole pages.) Commented Aug 4, 2013 at 14:10
  • One more problem I encountered: it produces strange wrong border lines on non-complete pages before \clearpage Is this a known and understood problem? Not always, but sometimes. Commented Aug 4, 2013 at 14:38
  • The problem can be seen at gitorious.org/primary-school-informatics-problems/2013_mathinf/… in 1_klass.pdf produced from 1_klass.tex Commented Aug 4, 2013 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .