[Tex/LaTex] How to set colored ruled margins for different pages

header-footermargins

I want to write a LaTeX document, and I want to have document rules (colored margins distinguishing sections and/or even/odd pages).

Here is a model of what I have in mind:

Page preview for final document

How can this be accomplished?

I have seen this question which is the most relevant question to what I have in mind, however it doesn't quite accomplish my goal.

I have also searched around in Google, and the best I have come up with is used "framed" package, which again, does not accomplish this task. I am sure that this can be done, though.

Best Answer

Here is a possible solution based on the following packages:

Notice that two compilation runs are necessary to successfully color the margins.

Code:

\documentclass{article}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage{ifthen}
\usepackage[contents={},opacity=1,scale=1.485]{background}

\AddEverypageHook{%
\ifthenelse{\isodd{\thepage}}%
{\backgroundsetup{angle=0,position={0.9\textwidth,-
.7\textheight},%
contents={\tikz[remember picture,overlay]{ %
\coordinate (x) at (current page marginpar area.south east|-current page.south east);
\draw[draw=none,fill=magenta!20]([xshift=-\textwidth]x)rectangle(current page.north west);}}}}%
{\backgroundsetup{angle=0,position={0.9\textwidth,-
.7\textheight},%
contents={\tikz[remember picture,overlay]{ %
\coordinate (x) at (current page marginpar area.south east|-current page.south east);
\draw[draw=none,fill=orange!20](x)rectangle(current page.north east);}}}}%
\BgMaterial}

\usepackage{lipsum} % dummy text

\begin{document}
\lipsum[1-30]
\end{document}

Result (just the first two pages are displayed):

enter image description here