I will try to explain a little bit because the OP is asking about reasons.
Keep in mind that there are two methods to place a node on a line or curve: explicit placement and implicit placement.
- Explicit: putting the node after ending point of the line/curve, e.g.
(a) .. controls (c) and (d) .. (b) node[pos=...] {...}
.
- Implicit: putting the node before ending point of the line/curve. e.g.
(a) -- node[pos=...] {...} (b)
.
The difference between them is that implicit placements inherit outer options (for example, options of tikzpicture
or scope
environment) when no inner options are given. But if inner options are given, it will be the final ones accepted by TikZ, no matter which type of placement you are using. See an example below:
\begin{tikzpicture}[pos=0.8]
\draw (1,0) -- (4,0) node {A}
(1,.5) -- (4,.5) node[midway] {A'};
\draw (1,1) -- node {B} (4,1)
(1,1.5) -- node[midway] {B'} (4,1.5);
\end{tikzpicture}
You will get something like below:
Ok, let' back to the original OP question.
One question is about the reason. I've explained some above. Actually, I don't really know the exact reason behind; but it's always safer to implicitly place nodes when no outer options need to be inherited. (UPDATE: the to
operation only allows implicit placement)
So please use:
\draw (0,0) to[out=90, in=-180] node [pos=0.5] (mid2) {} (5,5);
Another question is how to put a node using a given absolute position with respect to the line. If you mean "2/3 inch" along the curve, I'd say I have no idea how to achieve that.
(this is the first time I add another answer --- if it's not the correct thing to do, please tell me; but this is so different from my first one that... should I mark it community wiki?)
You can use a transform
on a decoration, thanks to the fact that the coordinate system in a decoration is along the path; that will shift the node after the end of the path by a distance specified as the second argument:
\documentclass[border = 2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
endnode/.style n args={2}{
decoration={
markings,
% transform={xshift=0.1*\pgfdecoratedpathlength}, % relative to lenght
transform={xshift=#2}, % absolute
% maybe add a endnodestyle like in Torbjørn T.'s answer
mark=at position 1 with {\node[draw=red] {#1};} % just to debug
},
postaction={decorate},
},
]
\foreach \Ang/\Len in {0/1,45/1.2,90/1.4,135/1.6,180/1.8,225/2,270/2.2,315/2.4}
{
\draw [endnode={A}{2mm}] (0,0) -- (\Ang:\Len);
\draw [endnode={B}{4mm}] (6,0) to[bend right] ++(\Ang:\Len);
}
\end{tikzpicture}
\end{document}
This makes the node centered at a fixed distance from the end of the path, along the path. It doesn't change the node anchors, unfortunately... and auto
is not working here.
Thanks to: Length of curve in TikZ, Torbjørn T.'s answer, \tikzset key with multiple arguments.
Best Answer
This is what the
auto
option does. By default it places the nodes on the left side of the line, looking along the path. You can move it to the other side by adding theswap
option.