# TiKZ-picture fitted to page edge

Using TiKZ, I'm trying to create an image that fits the margin of odd-sided pages (a water stamp of sort) for an A6 booklet. My idea was at first to create an image that is exactly the same size as an A6 page, compile to PDF and then use eso-pic to set it as the background of the booklet document.

However, I've realized I want to use commands such as \thesection to show information in the margin, so I'd rather do this in a way where everything fits in the same document. An example of what I want to accomplish can be seen here, where the document shows an A4 with eight A6 pages, the first one being odd-numbered.

I can't figure out how to scale the tikzpicture to fit the page exactly. Some parts of the image should be fitted to the page edge, so I need it to scale exactly, without margins. You could say I'm trying to do this, only the opposite.

-

\documentclass[10pt]{scrartcl}
\usepackage[margin=20mm,a6paper]{geometry}
\usepackage{tikz}
\usepackage{xifthen}
\usetikzlibrary{fit,calc}
\usepackage{lipsum}
\usepackage{everypage}

\parindent0mm

\newcommand{\currentsidemargin}{%
\ifodd\value{page}%
\oddsidemargin%
\else%
\evensidemargin%
\fi%
}

\ifthenelse{\isodd{\thepage}}
{   \begin{tikzpicture}[overlay, remember picture]
\path (current page.north west) ++(\hoffset, -\voffset) node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\paperwidth, minimum height=\paperheight] (pagearea) {};
\path (pagearea.north west) ++(1in+\currentsidemargin,-1in-\topmargin-\headheight-\headsep) node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\textwidth, minimum height=\textheight] (textarea) {};
\node[inner sep=0,fit=(pagearea.north east)(textarea.north east)(pagearea.south east)] (marginbox) {};
\draw (marginbox.south east) rectangle (marginbox.north west);
\draw (marginbox.south east) -- (marginbox.north west);
\end{tikzpicture}
}{}
}

\begin{document}

\lipsum[1-10]

\end{document}


-
This is fantastic! Will be tried out immediately! =) – Tomas Lycken Jun 28 '12 at 22:01
I was able to modify this to suit my needs perfectly. The key to success was nesting tikzpictures, with the node anchored to current page.north east. Thanks a lot! – Tomas Lycken Jun 28 '12 at 23:29

I don't exactly understand the question but you can produce your pages rather bluntly and then combine them via for example Can I convert a 16 page pdf into an 8x2 matrix in LaTeX?

For the multiple page file you can use something like

\documentclass{article}
\usepackage[paperheight=148mm,paperwidth=105mm]{geometry}
\usepackage{tikz,lipsum}

\begin{document}
\thispagestyle{empty}

\begin{tikzpicture}[remember picture,overlay]
\draw[line width=5mm,red!20]
([shift={(-0.5\pgflinewidth,-0.5\pgflinewidth)}]current page.north east)
rectangle
([shift={(0.5\pgflinewidth,0.5\pgflinewidth)}]current page.south west);
\node[scale=3,opacity=0.2,rotate=60] at (current page.center) {\textsf{First Watermark}};
\end{tikzpicture}
\lipsum[2]
\newpage
\thispagestyle{empty}

\begin{tikzpicture}[remember picture,overlay]
\draw[line width=5mm,blue!20]
([shift={(-0.5\pgflinewidth,-0.5\pgflinewidth)}]current page.north east)
rectangle
([shift={(0.5\pgflinewidth,0.5\pgflinewidth)}]current page.south west);
\end{tikzpicture}
\lipsum[3]
\end{document}


Note that you have to run twice for remember picture,overlay to work properly.

EDIT Only for the side of the page,

\documentclass{article}
\usepackage[paperheight=148mm,paperwidth=105mm]{geometry}
\usepackage{tikz,lipsum}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\draw[line width=5mm,blue!20]
([shift={(-0.5\pgflinewidth,\pgflinewidth)}]current page.north east)
--
([shift={(-0.5\pgflinewidth,0)}]current page.south east) node[circle,anchor=east,pos=0.2,fill,draw,text=black] {\Large $\Gamma$};
\end{tikzpicture}
\lipsum[3]
\end{document}


-
This is great, but it doesn't really answer to my main problem: how to fit the watermark to the edge of the page. Whatever I try, the picture is just enlarged to the left instead of moved to the right... – Tomas Lycken Jun 28 '12 at 19:08
Those rectangles are also watermarks. You can use the (current page) node to position your picture. Can you provide more details about the watermark even make a compilable example so that we can have a look at the positioning? – percusse Jun 28 '12 at 19:13