5

I am relatively new to Latex and I am struggeling with the use of the tikzpicture package.

What I want to do is to create a coloured column on the left side of every page in my document. Curently I am using the following code for this.

    \begin{tikzpicture}[remember picture,overlay]
    \node [rectangle, fill=sidecolor, anchor=north, minimum width=9cm, minimum height=\paperheight+1cm] (box) at (-5cm,0.5cm){};
    \end{tikzpicture}

The problem is that this code only produces a coloured bar on the first page of my document and does not extend it to multiple pages.

My question is therefore, how do i implement this tikzpicture to multiple pages in my document?. Does anyone have any insights on how to tackle this problem.

Note: I am not trying to make a header or footer.

Kind regards.

Thanks!

Balraj Boyal
  • 93
  • 2
  • 5

3 Answers3

7
  • Package atbegshi is an option for inserting material on every page at an absolute position.

  • Package xsavebox helps reducing the final PDF size when repeatedly inserting the same content.


\documentclass{article}

\usepackage{tikz}
\usepackage{xsavebox} %save content for repeated use
\usepackage{atbegshi} %insert material on every page

\usepackage{kantlipsum} %bla, bla

\xsavebox{PageBGPicture}{%
  \begin{tikzpicture}
  \node [rectangle, fill=yellow, minimum width=9cm, minimum height=\paperheight] (box) {};
  \end{tikzpicture}
}

%position background picture absolutely (w.r.t. upper left page corner) on every page
\AtBeginShipout{
  \AtBeginShipoutUpperLeft{\raisebox{-\height}{\xusebox{PageBGPicture}}}
}

\begin{document}
\kant[1-10]
\end{document}
AlexG
  • 54,894
  • Hello AlexG, Thanks this work with some tweaking. – Balraj Boyal Feb 19 '18 at 13:21
  • Thank you, it works. I would also need to change then the picture on every page. I mean, for the first chapter I want to use a certain picture. For the 2nd chapter another picture, and so on. Do you know how to do it? – nicolass Sep 04 '22 at 12:13
2

Just for fun, something using eso-pic. Node that I made your node names unique by adding the page number.

\documentclass{article}
\usepackage{tikzpagenodes}
\usepackage{lipsum}
\usepackage{eso-pic}
\begin{document}
 \AddToShipoutPicture{%
\begin{tikzpicture}[remember picture,overlay]
 \node [rectangle, fill=blue, anchor=west, minimum width=9cm, minimum height=\paperheight+1cm] 
 (box\thepage) at 
 (current page text area.west){};
\end{tikzpicture}}
\lipsum[1-8]
\end{document}
1

Use the atbegshi package.

\usepackage{atbegshi}

\AtBeginShipout { \begin{tikzpicture}[remember picture,overlay] \node [rectangle, fill=sidecolor, anchor=north, minimum width=9cm, minimum height=\paperheight+1cm] (box) at (-5cm,0.5cm){}; \end{tikzpicture} }