TikZ: How to set a node on an exact position on a line?

to set a node on a line the usual way should be something like this:

\begin{tikzpicture}
% place nodes
\node[draw] at (0, 0)   (a) {A};
\node[draw] at (5, 0)   (b) {B};

\node[draw] at (0, -2)  (c)     {C};
\node[draw] at (5, -2)  (d)     {D};

% draw edges
\draw[] (a) -- (b)  node[near start, above] {$x(kT)$};
\draw[] (c) -- (d)  node[near start, above] {$y(kT)$};
\end{tikzpicture}


But here i find it a little bit annoying, that the position of the node depends on the length of the line (what i try to illustrate in the above example). What i want is, that the nodes are exactly on the same position. To achieve this i have to write this:

\begin{tikzpicture}
% place nodes
\node[draw] at (0, -4)  (a2)    {A};
\node[draw] at (3, -4)  (b2)    {B};

\node[draw] at (0, -6)  (c2)    {C};
\node[draw] at (5, -6)  (d2)    {D};

% draw edges
\draw[] (a2.east)   -- (b2) node[at start, above right] {$x(kT)$};
\draw[] (c2.east)   -- (d2) node[at start, above right] {$y(kT)$};
\end{tikzpicture}


So my question is, is there a more intuitive way to do such things (something like the near start/at start node option)?

• Like the pos=## key for ## between [0,1]? – percusse Nov 26 '13 at 14:11
• a little shorter: \draw[] (a2.east) node[above right] {$x(kT)$} -- (b2); – someonr Nov 26 '13 at 14:26
• Have a look at the section "Coordinate Calculations" in the TikZ manual. – user10274 Nov 26 '13 at 15:30
• Ok sorry, i think i did not state this. I do not want calculate this for every node. The pos=## key is only a more variable position statement. The bahaviour is like the near start/midway key isn't it? Further I do not find an overall key in the coordinate calculation section. So i think the shortest solution is what @someonr suggested. – thomas Nov 26 '13 at 16:43
• The keys at start, near start and midway are just wrappers for pos (0, .25 and .5 respectively). All will depend on the length of the line and the position of the nodes (as well as their shape), if you count 0 times length as dependent of the length. If you just want to place a node at the .east anchor of the a2 nodes you can do this as @someonr showed, with the label option or even without the line (\node at (a2.east)). Can you elaborate on what you want to achieve here? What should an “overall key” be? place it like I want it? – Qrrbrbirlbel Nov 26 '13 at 18:45

Maybe this is too simplistic or not automatic enough for what you're really seeking, but I think based on the question text and comments that a simple xshift=<shift-dimension> will do. You can (optionally) wrap it into a style (here, near start abs) so the distance can be adjusted globally if needed.

\documentclass[tikz]{standalone}
\tikzset{near start abs/.style={xshift=1cm}}

\begin{document}
\begin{tikzpicture}
% place nodes
\node[draw] at (0, 0)   (a) {A};
\node[draw] at (3, 0)   (b) {B};

\node[draw] at (0, -2)  (c)     {C};
\node[draw] at (5, -2)  (d)     {D};

% draw edges
\draw[] (a) node[above,xshift=1cm] {$x(kT)$} -- (b);
\draw[] (c) node[above,xshift=1cm] {$y(kT)$} -- (d);
\draw (0,-3) node[above,near start abs] {Test} -- ++(7,0);
\end{tikzpicture}
\end{document}