1

In tikz you can position a node along a path using at start, midway or pos= syntax. This works fine, when using paths with -- syntax. I have noticed that tikz fails to position nodes correctly, when they use the to[] syntax instead.

Here is a trivial example of this behaviour:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
        \draw[thick] (0,2)  -- (5,2) node [midway, anchor=south] {Text} node [at start,anchor=north]{abcd} node [anchor=north,pos=0.8]{xyz};
        \draw[thick] (0,0)  to[out=0,in=180] (5,0) node [midway, anchor=south] {Text} node [at start,anchor=north]{abcd} node [anchor=north,pos=0.8]{xyz};
    \end{tikzpicture}
\end{document}

Here is what it looks like: Output showing two lines with nodes

The fact that the second line is a straight line is merely to stress that this is not related to the bending you can achieve with the to syntax. I would not normally use it for a straight line of course.

Is this intended and if yes, what would the best way to achieve the same output with the to syntax?

1

Just place your nodes before the second coordinates. This is also right with bended lines.

\documentclass[tikz,border=3.14mm]{standalone}

\begin{document}
    \begin{tikzpicture}
        \draw[thick] (0,2)  -- (5,2) node [midway, anchor=south] {Text} node [at start,anchor=north]{abcd} node [anchor=north,pos=0.8]{xyz};
        \draw[thick] (0,0)  to[out=0,in=180]  node [midway, anchor=south] {Text} node [at start,anchor=north]{abcd} node [anchor=north,pos=0.8]{xyz} (5,0);
    \end{tikzpicture}
\end{document}

placing nodes

1
  • 1
    Yes, I just edited it ^^
    – SebGlav
    May 30 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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