The TikZ documentation gives the following example for adding a label on an edge in a tree:
\begin{tikzpicture}
\node {r}
child {node {t}
edge from parent node {label}};
\end{tikzpicture}
Now, I want to tweak the way the edges are drawn. Namely, I want to be able to specify an arbirtary number of wires to link the two nodes. I'm pretty close to it, but I get stuck when I want to label midway, as in the example. My problem is with the following, stripped example:
[edge from parent path={%
\foreach \n in {0} { (\tikzparentnode) -- (\tikzchildnode) }}]
When this tweak is put, the label of the first example is stuck to the bottom of the picture. My first idea was to add a portion of path so that the node {label} can be attached to something. The closest I can get to is:
[edge from parent path={%
\foreach \n in {0} { (\tikzparentnode) -- (\tikzchildnode) };
\path ($(\tikzparentnode)!.5!(\tikzchildnode)$)}]
This terminates the path and starts a new one. Now, label gets positioned at the right place. But here is the odd thing. Let's define a counter to see how many of those paths are actually drawn (the expected value being 1) :
\newcounter{cnt}\setcounter{cnt}{0}
\begin{tikzpicture}%
[edge from parent path={%
\pgfextra{\addtocounter{cnt}{1}}%
\foreach \n in {0} { (\tikzparentnode) -- (\tikzchildnode) };
\path ($(\tikzparentnode)!.5!(\tikzchildnode)$)}]
\node (root) {r}
child {node {t}
edge from parent node {label}};
\end{tikzpicture}
\arabic{cnt}
With my previous fix, the path is drawn... 2 times! (I noticed that because with multiple wires, it is pretty obvious). Also, if I put a semicolon immediately after {label}, it seems that everything runs smoothly; trouble is, the usual syntax has to work too...
Summing up, my question is:
How can I redefine edge from parent path so that I can use a foreach in it, and still be able to place a label midway between the nodes?

let \p1 = ($ (\tikzparentnode)!.5!(\tikzchildnode) $) in (\p1) -- (\p1), but this is not entirely satisfactory: the followingnodewill be positioned at the right position, but, of course, I can't change it using[pos=]. – Michaël Sep 22 '10 at 18:54