Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Consider the following:

Let's say I have a dot. I would like to be able to position this dot anywhere on the page: at the corner, in the middle, anywhere.

So far, despite poring over manuals and experimenting, I can not figure out how to do this. It seems logical that there would be some system that would place a conceptual grid on the page and then allow for an exact placement within that grid.

I'm sure it exists, but I can't seem to find it.

I can make the dot, and all sorts of other shapes, but I just don't seem to have any control over where these shapes appear on the page.

I'm sure this is an obvious question and I have overlooked something.

share|improve this question
add comment

1 Answer

up vote 23 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.