Positioning relative to page in TikZ

Yes, it really does exist and is quite easy to use.

There are quite some subtleties in this as it can be cumbersome to use in several packages. The reason is that the compilation of the document has to be done several times in order to get the correct placement on the screen.

For instance, an A4-paper is not the size of an A3-paper, secondly you can not know the exact page size due to various packages in the making of the document.

One of the packages that is very nice to use this feature in is the beamer package. If you need this method in that package you are required to add fragile to the frame (ensures that the compilation will not fail with dubious error messages).

First of all you need to apply the remember picture to the tikzpicture environment. This enables tikz to save the picture size and various segments in the picture. Secondly you need to specify the overlay option which puts the picture out of the text-segment, allowing it to be placed on top of text without taking up any space. If you do not specify overlay it will be a regular text-box which is placed next to the preceding TeX-box. This is often not desirable when positioning relatively on the page. (Try and remove overlay from the example below and see the picture going out of bounds)

Now, in order to access the page you need the current page node which is referring to the rectangular shape that takes up the entire page. Thus you can refer to anchors and whatever you need via this.

Here is an example which gives you an idea...

\documentclass{article}
\usepackage{tikz}
\usepackage[paperheight=8cm,paperwidth=12cm]{geometry}
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[remember picture,overlay]
  \foreach \bound in {north,south,west,east,45} {
      \node[anchor=\bound] at (current page.\bound) {I am \bound-bound...};
  }
  \node at (current page.center) {I am NOT MOOVING!};
  % You can see the border of the page node with this:
  \draw[thick] (current page.south west) rectangle (current page.north east);
\end{tikzpicture}
\end{document}

And the result is: enter image description here

Relative coordinate system

I wished to elaborate on this and also help those who wants the actual relative coordinate system of the page. You can also do this by other means, but for easy reference and clear cut code a coordinate system transformation is very easy to understand.

So basically what I have done is creating a page cs transformation which transfers the page into a grid as shown in the below code (describing the cs by (-1,-1) rectangle (1,1)).

For this you need the \tikzdeclarecoordinatesystem in order to redefine a cs. You can check out this in the manual if in doubt of how it is used.

% Defining a new coordinate system for the page:
%
% --------------------------
% |(-1,1)    (0,1)    (1,1)|
% |                        |
% |(-1,0)    (0,0)    (1,0)|
% |                        |
% |(-1,-1)   (0,-1)  (1,-1)|
% --------------------------
\makeatletter
\def\parsecomma#1,#2\endparsecomma{\def\page@x{#1}\def\page@y{#2}}
\tikzdeclarecoordinatesystem{page}{
    \parsecomma#1\endparsecomma
    \pgfpointanchor{current page}{north east}
    % Save the upper right corner
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    % save the lower left corner
    \pgfpointanchor{current page}{south west}
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    % Transform to the correct placement
    \pgfmathparse{(\pgf@xc-\pgf@xb)/2.*\page@x+(\pgf@xc+\pgf@xb)/2.}
    \expandafter\pgf@x\expandafter=\pgfmathresult pt
    \pgfmathparse{(\pgf@yc-\pgf@yb)/2.*\page@y+(\pgf@yc+\pgf@yb)/2.}
    \expandafter\pgf@y\expandafter=\pgfmathresult pt
}
\makeatother

This will allow you to do the following:

\begin{tikzpicture}[remember picture,overlay,every node/.style={anchor=center}]
  \node at (page cs:0.5,0.3) {0.5,0.3};
  \node at (page cs:-0.25,0.3) {-0.25,0.3};
  \node at (page cs:0,0) {0,0};
  \draw(page cs:-0.25,0) -- (page cs:.75,-0.5);
  \draw[thick] (page cs:-1,-1) rectangle (page cs:1,1);
\end{tikzpicture}

which results in: enter image description here


I have found an easier solution for absolute coordinate positionning

(0,0) is on the top left corner of the page and (1,1) on the bottom right corner of the page

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}
\begin{document}
\begin{tikzpicture}[remember picture,overlay,shift=(current page.north west)]
\begin{scope}[x={(current page.north east)},y={(current page.south west)}]
\draw[thick,red,->,line width=1cm,] (0,0) -- (0.5,0.5) ;
\end{scope}
\end{tikzpicture}
\end{document}

If you want (0,0) to be on the bottom left and (1,1) on the top right corner of the page you just need to change the lines above as the following:

\documentclass{article} 
\usepackage{tikz} 
\usetikzlibrary{calc,arrows} 
\begin{document} 
\begin{tikzpicture}[remember picture,overlay,shift=(current page.south west)]
\begin{scope}[x={(current page.south east)},y={(current page.north west)}]
\draw[thick,red,->,line width=1cm,] (0,0) -- (0.5,0.5) ; 
\end{scope}
\end{tikzpicture} 
\end{document}