TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was working on a figure, and for some reason relative coordinates have stopped working (it did before). I removed all code down to a bare minimum, and they still don't work. I don't know what I've done wrong so I'll just include it here:



  % Nodes
  \node at (0, 0) (input) {i};
  \node at ++(2, 0) (p1) {a};
  \node at ++(2, 0) (p2) {b};

In this example, a and b are positioned on top of each other instead of next to each other. Why?

share|improve this question
up vote 9 down vote accepted

Because they are relative to the same coordinate (0,0). If you replace the last line in the tikzpicture environment with \node at ++(4, 0) (p2) {b}; it moves. Or if you want to define node positions relative to other nodes you can use.

  \node at (0, 0) (input) {i};
  \node at ($(input)+(2,0)$) (p1) {a};
  \node at ($(input)+(4,0)$) (p2) {b};

while having \usetikzlibrary{calc} in your preamble.

As Jake says, the ++(...) syntax works within a TikZ command and is relative to the last saved position. At the start of the line, the coordinate is set to (0,0) so each of your relative coordinates is relative to (0,0). To make each relative to the last, either use explicit coordinates/nodes as above or combine your statements into one:

\node {i} node at ++(2,0) (p1) {a} node at ++(4,0) (p2) {b};

Note that the first node doesn't need an explicit coordinate (via at) since it is placed at (0,0) which is the starting position of the path.

share|improve this answer
Your answer is completely correct but a bit sparse on details! I was about to write an answer to this question when your answer was posted, so I'd rather just edit the extra details in to your answer. Would that be okay? – Loop Space Sep 26 '11 at 13:05
@AndrewStacey Sure. I would be more than happy. – percusse Sep 26 '11 at 13:06
Done: The bit in yours that Jake was missing was the fact that the relative coordinates are relative to something: the initial position of the path. – Loop Space Sep 26 '11 at 13:12
@AndrewStacey : Thank you for the clarification. I can delete this if you want to make further elaboration. Let me know :) – percusse Sep 26 '11 at 13:30

... or (continuing @percusse's & @Jake's answer), since you are loading the positioning TikZ library anyway, you can write:

\begin{tikzpicture}[node distance=2cm, on grid]
% Nodes
\node at (0, 0) (input) {i};
\node (p1) [right=of input] {a};
\node (p2) [right=of p1] {b};

This makes the code much simpler to understand and you can change the distance between the nodes later on, by modifying only one number. You can even have 'groups' of nodes that are spaced differently, if you place within a scope environment.

Depending what your actual application is, you may want to take a look at the petri TikZ library (TikZ 2.10 manual - pp.394 - 398).

share|improve this answer

The ++ operator only works within one \draw, \fill, \path or \node command. To get the example to work as expected, use \path ++(2, 0) node (p1) {a} ++(2, 0) node (p2) {b};

share|improve this answer
Ah, of course. Simplest as usual! +1 – percusse Sep 26 '11 at 13:05

Your Answer


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.