# Place a TikZ picture on every page

I am looking to place a picture (TikZ picture) on every page of my document. How can I do that?

In essence I would like to control the placing of the image on even and odd pages. For example the holes on a folder sheet, these are placed to the left on odd pages and right on even pages.

## Edit

So I am using Peter Grill's version just to test and I have the following:

\documentclass[svgnames]{article}
\usepackage[left=2.5cm,right=2.5cm, top=3.75cm, bottom=3.5cm,letterpaper]{geometry}
\usepackage[all]{background}
\usepackage{lipsum,url}
\usepackage{amsmath,amssymb,enumitem,multicol}
\usepackage{tikz,bbding}
\usetikzlibrary{calc}
\usepackage{changepage}
\strictpagecheck

\newcommand*{\VOffset}{2cm}% vertical offset
\newcommand*{\HOffset}{1cm}% horizontal offset

\newcommand{\MyTikzLogo}{% For a logo drawn with TikZ
\begin{tikzpicture}[remember picture,overlay,draw=black,ultra thick]
\checkoddpage
\ifoddpage
\draw  [fill=gray!50] (\HOffset,-\VOffset) circle (0.5cm);
\draw  [fill=gray!50] ($(\HOffset,-\paperheight+\VOffset)$) circle (0.5cm);
\draw  [fill=gray!50] ($(\HOffset,-0.5\paperheight)$) circle (0.5cm);
\else
\draw  [fill=gray!50] (\paperwidth-\HOffset,-\VOffset) circle (0.5cm);
\draw  [fill=gray!50] ($(\paperwidth-\HOffset,-\paperheight+\VOffset)$) circle (0.5cm);
\draw  [fill=gray!50] ($(\paperwidth-\HOffset,-0.5\paperheight)$) circle (0.5cm);
\fi
\end{tikzpicture}
}

\SetBgContents{\MyTikzLogo}% Set tikz picture

\SetBgPosition{current page.north west}% Select location
\SetBgOpacity{1.0}% Select opacity
\SetBgAngle{0.0}% Select roation of logo
\SetBgScale{1.0}% Select scale factor of logo

\parindent0pt \parskip8pt
\begin{document}
\begin{tikzpicture}[overlay, remember picture]
\node[yshift=-3cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[draw=MidnightBlue,fill=MidnightBlue] (0,0) rectangle (0.75cm,3cm);%black
\draw[draw=gray!20,fill=gray!20] (0.75cm,0) rectangle (\paperwidth,3cm);%gray!20   or LightSkyBlue and \paperwidth-0.01cm
\end{tikzpicture}};
\path (current page.north west) ++(0.5,-1.55) node[rotate=90] {\color{white}\tiny revised \today};
\path (current page.north east) ++(-1,-1) node[below left] {Name: \rule{2in}{.4pt}};
\path (current page.north east) ++(-1,-1.5) node[below left] {Date: \rule{2in}{.4pt}};
\path (current page.north west) ++(1,-0.5) node[below right] {Course Name};
\path (current page.north west) ++(1,-1) node[below right] {University};
\path (current page.north west) ++(1,-1.5) node[below right] {Mathematics and Science Department};
\end{tikzpicture}
\section*{Lorem Ipsum}
\lipsum[1-25]
\end{document}


The problem that i have is that when I try to print, the file does not seem to fill the entire page. The header part is just for the first page, the other pages will only contain the course name.

An insight into the matter will help.

-
For what is worth, the luatex manual has a nice example of this. –  Marc van Dongen Jan 17 '12 at 16:59
See also Tikzpicture on every page. –  Hendrik Vogt Jan 17 '12 at 19:29

Here is a solution adapted from How do I add an image in the upper, left-hand corner using TikZ and graphicx. This uses the background package to place a tikzpicture on each page. The logic for controlling the behavior on odd and even pages comes from this solution to if then else for odd page even page.

The parameters \VOffset and \HOffset control the positioning of the hole images:

\documentclass[12pt]{book}
\usepackage[demo]{graphicx}
\usepackage[all]{background}

\usepackage{lipsum}
\usepackage{showframe}
\usepackage{tikz}
\usetikzlibrary{calc}

\usepackage{changepage}
\strictpagecheck

\newcommand*{\VOffset}{2cm}% vertical offset
\newcommand*{\HOffset}{1cm}% horizontal offset

\newcommand{\MyTikzLogo}{% For a logo drawn with TikZ
\begin{tikzpicture}[remember picture,overlay,draw=black,ultra thick]
\checkoddpage
\ifoddpage
\draw  [fill=gray!50] (\HOffset,-\VOffset) circle (0.5cm);
\draw  [fill=gray!50] ($(\HOffset,-\paperheight+\VOffset)$) circle (0.5cm);
\draw  [fill=gray!50] ($(\HOffset,-0.5\paperheight)$) circle (0.5cm);
\else
\draw  [fill=gray!50] (\paperwidth-\HOffset,-\VOffset) circle (0.5cm);
\draw  [fill=gray!50] ($(\paperwidth-\HOffset,-\paperheight+\VOffset)$) circle (0.5cm);
\draw  [fill=gray!50] ($(\paperwidth-\HOffset,-0.5\paperheight)$) circle (0.5cm);
\fi
\end{tikzpicture}
}

\SetBgContents{\MyTikzLogo}% Set tikz picture

\SetBgPosition{current page.north west}% Select location
\SetBgOpacity{1.0}% Select opacity
\SetBgAngle{0.0}% Select roation of logo
\SetBgScale{1.0}% Select scale factor of logo

\begin{document}
\section*{Lorem Ipsum}
\lipsum[1-25]
\end{document}

-
I edited your sample above (I edited my post to show the code) but when I add my code and tried to print, the document doesn't fit in the entire page. Why? –  azetina Jan 17 '12 at 20:03
I compiled your code and looks fine in the PDF. I suspect it is a problem with your printer or settings, not being able to print right to the edge of the page. –  Peter Grill Jan 17 '12 at 20:20
I don't understand what the problem is but if you check File>Print you will see may be that the document does not print correctly with an offset at the top and bottom by about 0.75cm even though I have select a letter paper size in the geometry section. –  azetina Jan 17 '12 at 21:51
Like I said I believe it is because the printer can not print to the edge of the paper, and the previewer is showing you that. You should post a separate question as that seems unrelated to placing a tikz picture. –  Peter Grill Jan 17 '12 at 22:06
Will do inquire... –  azetina Jan 18 '12 at 13:28

An alternative to fanchydr is scrpage2 (a part of KOMA-Script).

Example:

\documentclass{book}

\usepackage{tikz}
\usetikzlibrary{calc}

\usepackage{scrpage2}
% right head on even page
\rehead{\tikz[overlay, remember picture]\fill [red] ($(current page.north east)-(2,10)$) circle (2mm);}
% left head on odd page
\lohead{\tikz[overlay, remember picture]\fill [green] ($(current page.north west)+(2,-10)$) circle (2mm);}

\usepackage{lipsum}

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


You may also have a look at Page border coloured

-

Here's a solution using fancyhdr and textpos to trick fancyhdr into putting a header (or footer, in this case) outside the specified areas. You'll have to adapt the other headers/footers to your liking (see the fancyhdr manual.) It doesn't matter where in the header/footer you put the textblock, you just have to differentiate between even and odd pages.

\documentclass[a4paper,twoside]{article}% to get even and odd pages

\usepackage{fancyhdr}

\usepackage{tikz}

\newcommand{\mytikzpic}{\tikz \shade[left color=yellow,right color=blue] (0,0) circle (1.25cm);}

\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{10mm}% 1 generic horizontal unit is equivalent to 10mm
\setlength{\TPVertModule}{10mm}% 1 generic vertical unit is equivalent to 10mm
\textblockorigin{0mm}{0mm}% top left corner set as origin

\pagestyle{fancy}

\fancyfoot[LO]{
\begin{textblock}{3}(17.5,10)
\mytikzpic
\end{textblock}
}
\fancyfoot[RE]{
\begin{textblock}{3}(0.5,10)
\mytikzpic
\end{textblock}
}

\usepackage{lipsum}% just for filler text

\begin{document}
\lipsum
\end{document}


-

The package fanchydr was written for exactly this purpose: putting something on every page of a document, optionally different on even and odd pages.

-
I am not trying to control the header and footers but rather the margins as the image would be placed there possibly alternating if even or odd like the example i cited above. I have used fanchydr but probably am not an expert at. Probably an example would help me understand. –  azetina Jan 17 '12 at 16:39
fanchydr can put the image on margins as well. Take a look at Chapter 20 (A movie) of the fancyhdr documentation - perhaps the example here is illuminating. –  Boris Jan 17 '12 at 16:48
I will take your advice into consideration –  azetina Jan 18 '12 at 13:27

The fortextbook option of eqexam can put a picture (in the margin) of every page.

-