[Tex/LaTex] TiKZ-picture fitted to page edge

marginstikz-pgf

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.

Best Answer

How about this, it makes use of Martin Scharrer's answer in this answer:

\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%
}

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

enter image description here

Related Question