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 wonder why we need a different syntax for specifying nodes (and coordinates) on a path when using the simple -- and the .. controls … system or the to operation.

Here’s an example to illustrate the problem:


\tikzset{every node/.style={fill=white,inner sep=2pt}}

    \draw [thick] (0,0) -- (5,2)
        node [pos=0.2] {A}
        node [midway] {B};

    \draw [thick] (0,0) .. controls +(1,2) and +(-2,-1) .. (5,2)
        node [pos=0.2] {A}
        node [midway] {B};

\begin{tikzpicture}% with wrong result
    \draw[line width=1pt](0,0) to[out=40, in=160] (5,2)
        node [pos=0.2] {A}
        node [midway] {B};

    \draw[line width=1pt](0,0) to[out=40, in=160] 
        node [pos=0.2] {A}
        node [midway] {B} (5,2); 

When using -- or controls it is possible to position the node after the second coordinate.

simple -- controls operation

But with to[in=x, out=y] this won’t work

to problem

all nodes go to (0,0) (not the first coordinate it’s always (0,0)) an we must gove the nodes before the second coordinate right after the to operation

right to result

I guess this has to do with the way to works but I wonder why …?

share|improve this question
I think this is explained in page 149 of the manual and that should be something to do with \pgfpointcurveattime command population. Also as a sidenote, it is now possible to put a node in the middle of an arc with the cvs version of pgf-tikz implemented in March. – percusse Apr 6 '12 at 10:43
"With great power comes great responsibility". The to syntax is incredibly powerful and flexible, but as part of that it needs more precise input. Relevant to this question, the to path is meant to figure out where the nodes go, and this can be done in any way desired (including ignoring the pos keys). But to do this, the to path constructor needs to know the nodes on its path at construction time, which (as TikZ works as a parser) is when the target coordinate is read. Hence for the best results, nodes should be specified before the target coordinate, not after. – Loop Space Apr 6 '12 at 15:07
@AndrewStacey: OK, I see … if you make this to an answer I’d accept it. Is your “nodes should be specified before the target coordinate” meant only for two or in general including --, |- and controls etc.? – Tobi Apr 6 '12 at 15:15
Converted, and hopefully addressed that last point. – Loop Space Apr 6 '12 at 17:05
up vote 7 down vote accepted

The to path mechanism is extremely powerful. Essentially, using a to path one can put anything on the path at the current stage in its construction. When constructing a path segment, the to path machine needs to know the starting coordinate, the target, and any nodes to be placed on the path. The latter is because the to path should have complete control, including deciding how to interpret the various ways of positioning a node on a path segment.

TikZ's path constructor works like a parser. So it eats the input line, spewing out PGF commands as it goes along. A to path constructor is invoked when the target coordinate is reached (but before it is processed). Therefore any nodes that are to be involved in the to path construction have to be read before the target is specified. It may be possible to specify nodes after the target, but whether or not this works will depend vastly on what the to path actually does. In some simple cases, it simply inserts a more normal segment into the current path specification, in which case putting the nodes afterwards ought to work. But if it does something more complicated then it will not.

With more simply path specifications, such as --, -|, or .. controls .., then TikZ knows how the path will look so when handling nodes it can be a little more flexible as to when they are specified: there's no potential for surprises.

share|improve this answer
Thanks! That answers my question. I guess I was confused because I thought that -- is an abbreviation/synonym of to[] (without any options). – Tobi Apr 6 '12 at 17:16
It is, but it's the other way around. The default to action is to insert -- node stuff (target coordinate) into the path. – Loop Space Apr 6 '12 at 21:30
Ahh, then my intuition wasn’t so wrong :-) – Tobi Apr 6 '12 at 22:48

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.