Following Roel's answer to How to write a tree with no (visible) root with TikZ? I attempted to visualise my Huffman-Code for "Tennessee", but it didn't turn out as I expected:
My MWE:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees,arrows}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[-,>=stealth',level/.style={sibling distance = 3cm, level distance = 1.5cm}]
\coordinate
child {node [circle,draw] {E} edge from parent node[left] {\textcolor{red}{0}}}
child {edge from parent node[right]{\textcolor{red}{1}}
child {node [circle,draw] {S} edge from parent node[left] {\textcolor{red}{0}}}
child {edge from parent node[right]{\textcolor{red}{1}}
child {node [circle,draw]{N} edge from parent node[left] {\textcolor{red}{0}}}
child {node [circle,draw]{T} edge from parent node[right] {\textcolor{red}{1}}}
}
};
\end{tikzpicture}
\end{document}
Obviously the numbering on the edges is not being level and more importantly, the edges are overlapping.
I experimented with removing the style, but that just leaves the tree narrower yet does not resolve the issue of the missing edge alignment.
Best Answer
You are supposed to put the
edge from parent
operation at the end of the correspondingchild
path declaration, like in the following :I added styles to get a cleaner code, and redefined
edge from parent path
to align the nodes (redefiningchild anchor
andparent anchor
should be enough, but there seems to be a bug with it in my version of Tikz)