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 wonder is that possible to use absolute coordinates regarding all document? Please see my example

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\filldraw[red]
(30pt, 9pt) -- (130pt, 9pt);
\end{tikzpicture}

\begin{tikzpicture}
\filldraw[blue]
(3pt, 9pt) -- (130pt, 9pt);
\end{tikzpicture}

\end{document} 

enter image description here

Why red and blue lines have the same left x-coordinate? I would like to move the second on 27pt left!

share|improve this question
2  
Try putting both drawings in one begin{tikzpicture} ... end{tikzpicture} environment. –  percusse Feb 6 '12 at 19:06
    
In that case the second line will be drawn over the first. –  Michael Z Feb 6 '12 at 19:10
    
It seems that you only want the x coordinate to be absolute, but the y coordinate to be relative. Is that right? –  Loop Space Feb 6 '12 at 19:54
    
Actually not. I have mentioned x as example I would like to have relative (x,y)-coordinates. –  Michael Z Feb 6 '12 at 20:43
    
You said "absolute" in the question, but in the comment you said "relative". If "relative" is correct, then the key question is "relative to what?". –  Loop Space Feb 7 '12 at 9:51
show 1 more comment

4 Answers

up vote 8 down vote accepted

To automatically make all tikzpictures align on the origin, you can set \tikzset{every picture/.append style={trim left=0}}. This sets the left margin to be at the x position of the origin. Note that you will run into trouble if you use negative coordinates, since these will protrude out of the image. In that case, you'd have to set trim left to a negative value that is large enough to include all points.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{every picture/.append style={trim left=0}}
\begin{tikzpicture}
\filldraw[red]
(30pt, 9pt) -- (130pt, 9pt);
\end{tikzpicture}

\begin{tikzpicture}
\filldraw[blue]
(3pt, 9pt) -- (130pt, 9pt);
\end{tikzpicture}

\end{document} 
share|improve this answer
    
What about y-coordinate? Can I use similar approach? –  Michael Z Feb 9 '12 at 14:12
    
Do you want to overlay the pictures, so that the point (0,0) is the same point on the page, even if you use them in different tikzpictures, or do you want the y positions of two tikzpictures that are next to each other to be the same? –  Jake Feb 9 '12 at 14:14
    
I want the first. –  Michael Z Feb 9 '12 at 16:21
    
Why don't you want to put both drawings into the same tikzpicture? –  Jake Feb 9 '12 at 16:23
    
Because the second drawing is NOT TikZ drawing. I have one TikZ figure and one figure composed with \qbezier s. I want to depict them together, overlapping each other! –  Michael Z Feb 9 '12 at 16:35
show 2 more comments

The answer is suggested by percusse. Each tikzpicture is typeset in its own box. The box is made as small as possible to typeset all what's in it. For example, a tikzpicture consisting of a square with lower left position (1,1) and upper right position (2,2) will still have a width of 1cm and a hight of 1cm.

The coordinates in your tikzpictures are completely relative to their own tikzpictures. This explains why you cannot relate the coordinates in one tikzpicture to those of another tikzpicture (unless you're using remember pictures).

share|improve this answer
    
OK, thanks for explanation! But is that possible to use to TikZ coordinates in the same coord system as native LaTeX use? I mean here when I put (1,2) point in TikZ environment it will be put in the same place where \begin{picture}(0,0) \put(1,2){Point} \end{picture} will be put. –  Michael Z Feb 6 '12 at 19:33
    
I'm not sure if I understand what you mean with the same coordinate system. TikZ has several coordinate systems. One of the most popular notations for specifying coordinates is`(<x>,<y>), which is the implicit notation for the canvas coordinate system`. LaTeX picture coordinates are expressed in multiples of the length variable \unitlength, which defaults to 1pt. Perhaps if you can explain why you want to use the same coordinate systems we can see if there's a solution. –  Marc van Dongen Feb 6 '12 at 22:15
    
I tried to rephrase my previous comment but the system didn't let me. If you redefine \unitlength to 1cm (\setlength{\unitlength}{1cm}) you can specify coodinates in a similar way as in the TikZ canvas coordinate system. –  Marc van Dongen Feb 6 '12 at 22:24
    
I am afraid me point you to the wrong way. We don't talk about units here. I just want to use TikZ primitives in the LaTeX canvas's coord system. I think that other responders have given the solution already... –  Michael Z Feb 7 '12 at 18:22
    
@MichaelZ No worries. Glad your problem's solved. –  Marc van Dongen Feb 7 '12 at 18:34
add comment

Add a origine with a node

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \node(O) at (0,0){};
    \coordinate(O) at (0,0);
    \filldraw[red]
    (30pt, 9pt) -- (130pt, 9pt);
\end{tikzpicture}

\begin{tikzpicture}
    \node(O) at (0,0){};
    \filldraw[blue]
    (3pt, 9pt) -- (130pt, 9pt);
    \end{tikzpicture}

\end{document}
share|improve this answer
add comment

In normal TeX there is a \phantom that is often used to leave the same amount of space as required by its arguments. You could do something similar by adding a \path (0pt,0pt) for both pictures. This ensures that the left hand side starts at the same x-coordinate:

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \path (0pt,0pt);
    \draw[red] (30pt, 9pt) -- (130pt, 9pt);
\end{tikzpicture}

\begin{tikzpicture}
    \path (0pt,0pt);
    \draw[blue] (3pt, 9pt) -- (130pt, 9pt);
\end{tikzpicture}
\end{document} 
share|improve this answer
    
Isn’t it possible to automate adding an orgin with the every picture style? –  Tobi Feb 6 '12 at 20:46
    
@Tobi: Good idea. Looks like Jake already posted that as an answer. But not sure you'd want to do that to every picture. –  Peter Grill Feb 6 '12 at 21:13
    
I don’t but the OP may want this ;-) Otherwise it should be easy to create a set orgin style with trim left=0 as @Jake posted. –  Tobi Feb 6 '12 at 21:18
    
Thanks! I think this is the most simple solution that can be applied to the each particular picture! –  Michael Z Feb 7 '12 at 18:24
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.