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:
Best Answer
You could use the option
midway
, like so:Code
Result