TransWikia.com

tikz node positioning on paths with to-syntax

TeX - LaTeX Asked on July 13, 2021

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?

One Answer

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

Correct answer by SebGlav on July 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP