4

How this can be done for ALL pages is explained in this thread: How to set colored ruled margins for different pages?

But I would like to know if it is possible to color the margins only for some pages? How would you do that?

So pages 1 to x no colors, then y pages of color and then no colors again.

6

Using the settings of the answer to the question linked, you can use a conditional to activate or deactivate the margins at will:

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

\newif\ifBgMat

\AddEverypageHook{%
\ifBgMat
\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
\else
\fi}

\usepackage{lipsum} % dummy text
\BgMattrue% activate colored margins
\begin{document}
\lipsum[1-8]

\clearpage
\BgMatfalse% deactivate colored margins
\lipsum[1-8]

\clearpage
\BgMattrue% activate colored margins
\lipsum[1-8]
\end{document}

enter image description here

  • Thank you the example works perfectly for the article document class but not for the revtex4-1 document class which I have to use. – Enders Jul 31 '13 at 7:02
5

You can define a pagestyle and use it when needed.

\documentclass[twoside]{article}

\usepackage{tikz}               % you know what this does!
\usetikzlibrary{calc}

\usepackage{fancyhdr}         % put things headers and footers and we plan misuse it ;)
\usepackage{lipsum}           % for sample text 

\fancypagestyle{mypage}{%
    \fancyhf{}
    \fancyhead[LO]{%
        \begin{tikzpicture}[overlay,remember picture]
            \fill [color=blue] (current page.north west) rectangle
                ($ (current page.south west) + (1cm,0cm) $);
        \end{tikzpicture}
        }
    \fancyhead[RE]{%
        \begin{tikzpicture}[overlay,remember picture]
            \fill [color=orange](current page.north east) rectangle
                ($ (current page.south east) + (-1cm,0cm) $);
        \end{tikzpicture}
        }
    \fancyfoot[C]{\thepage}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
}

\begin{document}
\pagestyle{mypage}   % activate colored margins
\lipsum[1-8]

\clearpage
\pagestyle{plain}    % deactivate colored margins
\lipsum[1-8]

\clearpage
\pagestyle{mypage}   % activate colored margins
\lipsum[1-8]

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.