# Positioning labels on edges of tikz-qtree

I'm making a tree in a document with tikz-qtree and I managed to make the tree. I've also added labels to the edges, without any problems. However, the labels appear at the top of the edge, i.e. a lot closer to the parent node than the child node. I'd like to have the labels in the middle. How can I accomplish that?

I checked out this question on positioning labels, but i can't figure out from the answer what it actually is they did...

My code is as followed:

\begin{tikzpicture}[every tree node/.style={draw,circle},
level distance=1.25cm,sibling distance=1cm,
edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}]
\Tree
[.a
\edge node[auto=right] {$[a]$};
[.b
\edge node[auto=right] {$[b]$};
[.1 ]
\edge node[auto=left] {$[b]$};
[.2 ]
]
\edge node[auto=left] {$[a]$};
[.c
\edge node[auto=right] {$[c]$};
[.3 ]
\edge node[auto=left] {$[c]$};
[.4 ]
]
]
\end{tikzpicture}


As provided in the answer, here the actual solution that I used (Note that Christian R.'s solution also works:

\begin{tikzpicture}[every tree node/.style={draw,circle},
level distance=1.25cm,sibling distance=1cm,
edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}]
\Tree
[.a
\edge node[auto=right,pos=.6] {$[a]$};
[.b
\edge node[auto=right,pos=.8] {$[b]$};
[.1 ]
\edge node[auto=left,pos=.8] {$[b]$};
[.2 ]
]
\edge node[auto=left,pos=.6] {$[a]$};
[.c
\edge node[auto=right,pos=.8] {$[c]$};
[.3 ]
\edge node[auto=left,pos=.8] {$[c]$};
[.4 ]
]
]
\end{tikzpicture}


Giving as result:

-
– Claudio Fiandrino Feb 14 '13 at 13:48

You could use the option midway, like so:

\edge node[midway,left] {$[b]$};


Code

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}[every tree node/.style={draw,circle},
level distance=1.25cm,sibling distance=1cm,
edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}]
\Tree
[.a
\edge node[auto=right] {$[a]$};
[.b
\edge node[midway,left] {$[b]$};
[.1 ]
\edge node[midway,right] {$[b]$};
[.2 ]
]
\edge node[auto=left] {$[a]$};
[.c
\edge node[midway,left] {$[c]$};
[.3 ]
\edge node[midway,right] {$[c]$};
[.4 ]
]
]
\end{tikzpicture}
\end{document}


Result

-
And if you want even finer control, you can use the pos=<value> key where <value> is a fraction of the total length. (I was about to add an answer like yours). – Alan Munn Feb 14 '13 at 14:25
@AlanMunn: Thanks, that totally worked! I was wondering if you could provide me some insight though. To get the labels at approximately the middle I had to use pos=.8 for the second row of labels and pos=.6 for the first. Why isn't it pos=.5? – Mythio Feb 14 '13 at 14:41
@Christian R.: Your solution works too, although it doesn't put the labels very neat. It works well enough though for most cases, and probably the position also depends on the other parameters like sibling spacing etc. – Mythio Feb 14 '13 at 14:42