[Tex/LaTex] Positioning node on tikz path

positioningtikz-pgf

I have trouble defining a node on a path. If the path is described using points and the in/outgoing angle, the node is always at the beginning. If the path is described with control points, it works flawlessly.

In the code below you see that one path correctly has a node about midway, whereas for the second path the node will be placed at the start of the path.

\documentclass[border=5pt]{standalone}

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{math,calc}

\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}
    \draw (0,0) .. controls (1,2) and (4,3) .. (5,5)
    node [pos=0.5] (mid1) {};
    \draw[fill] (mid1) circle (1pt);

    \draw (0,0) to[out=90, in=-180]  (5,5)
    node [pos=0.5] (mid2) {};
    \draw[fill] (mid2) circle (1pt);
\end{tikzpicture}
\end{document}

I have a path constructed as in the second example, how can a place a node at a specific relative position (2/3 in, say)?

I am also interested why tikz treads the two paths so differently and why "node [pos= ]" works in one of the cases, but not the other.

Best Answer

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: enter image description here


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.