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.

I would like to create layers/overlays in my document (inline which may depend on variables\macros such as page number/chapter or user defined stuff).

How can I create a TikZ image that is the size of the page (without hard coding the values), with the ability to easily anchor to the edges of the paper (I think this will be already possibly with TikZ)?

Basically I want my TikZ picture's canvas to be that of the page with (0,0) being the top-left corner so I can do normal TikZ plotting on the page.

Obviously it should easily work with two-sided docs and it shouldn't interfere with normal page layout.

Thanks

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

You can use the \AddToShipoutPictureBG command from the eso-pic package together with a \put(0,0){ ...} to place your tikzpicture in the upper left corner of the page. Usually, for positioning TikZ objects relative to the page, one would use \tikz[remember picture, overlay] together with the (current page) node, but that requires two compile runs. This approach only needs one.

If you then set x=\paperwidth, y=-\paperheight, the coordinate (1,1) will be the lower right corner.

You can then position objects within your tikzpicture as usual:

\node at (0,1) [anchor=south west, scale=4] {Lower Left};
\node at (1,1) [anchor=south east, scale=4] {Lower Right};
\node at (0,0) [anchor=north west, scale=4] {Upper Left};
\node at (1,0) [anchor=north east, scale=4] {Upper Right};
%       \fill [ultra thick, orange] (0.5,0.5) circle [radius=2cm];
\draw (0,0) -- (1,1);

will produce

\documentclass{article}

\usepackage{tikz}
\usepackage{longtable}
\usepackage{afterpage}
\usepackage{lipsum}
\usepackage[texcoord]{eso-pic}

\begin{document}\lipsum[3]
\AddToShipoutPictureBG*{%
    \put(0,0){%
        \tikz [
            overlay,
            x=\paperwidth,
            y=-\paperheight] {
                \node at (0,1) [anchor=south west, scale=4] {Lower Left};
                \node at (1,1) [anchor=south east, scale=4] {Lower Right};
                \node at (0,0) [anchor=north west, scale=4] {Upper Left};
                \node at (1,0) [anchor=north east, scale=4] {Upper Right};
%
                \fill [ultra thick, orange] (0.5,0.5) circle [radius=2cm];
                \draw (0,0) -- (1,1);
        }
    }
}
\end{document}
share|improve this answer
    
Thanks. I don't know why there are problems with your code or my production code but sometimes the position gets messed up(Seems like the origin is wrong). Does the code need to be compiled twice in some cases to update the aux file or whatever? (and if so anyway around that as it becomes counter productive to recompile just to get the correct size of the page(which should be known at compile time) –  AbstractDissonance Jul 13 '12 at 16:22
    
@AbstractDissonance: Yes, it needs to be compiled twice, sorry for not mentioning that. It's not quite as simple as just knowing the correct size of the page, the problem is with the positioning: Which page are we on? That's what causes the need for the two compile runs. There's no way around that, but it's not behaviour that's unique to this application: Many (La)TeX features require multiple compile runs. –  Jake Jul 13 '12 at 16:25
    
Well, it is useless then for my application(it already takes minutes to compile and I'm not even 5% finished) and I really don't see why it should require two compiles. EVERY PAGE has the same structure except possibly for two sided pages which can be handled with conditionals. If my page is 8x11 then I simply want to put some tikz picture at some point relative to the corners of the page. If I change the size to 10x11 then I want the positions to still be relative to the corners. I would think all I need to do is tell tikz to create a picture of size wxh and center it? –  AbstractDissonance Jul 13 '12 at 16:31
    
BTW, I'm using the everypage package to hook on to the page so maybe that will remove the need to recompile twice? –  AbstractDissonance Jul 13 '12 at 16:33
    
@AbstractDissonance: I've edited my answer to show an approach that does not need two compile runs. For the future, it's a good idea to post a minimal example and include as much information as possible. You didn't mention that you need to put the pictures on "EVERY PAGE"... –  Jake Jul 13 '12 at 16:42
show 3 more comments

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.