[Tex/LaTex] How to draw empty nodes in tikz-qtree

tikz-qtreetikz-treestrees

I'm new to tikz-qtree, and I would like to reproduce this figure in LaTeX:

enter image description here

So far, I've managed to cobble this bit of code, but the results are a bit comical, as the empty nodes (those without text) appear smaller than the nodes with text. Secondly, I haven't quite managed to put text above a node or opposite a node/edge as shown in the figure.

How do I get the circles to be all of same radius irrespective of whether empty/filled?

\begin{tikzpicture}[every tree node/.style={draw,circle}]
\Tree[.{Root}
   [.4 11 {} ]
   [.5 6  {} ]
   ]
\end{tikzpicture}

I reckon to do that, I might need to specify a new node with a fixed radius using \newcommand right? However, my attempts have been unsuccessful.

Best Answer

You can specify a minimum size for the nodes, and fix the sibling and level distances. To draw the annotations to match the levels, we make another tree with empty branches but with the same level distance. To keep the style parameters separate, each tree is wrapped in its own {scope} environment.

\documentclass{article}
\usepackage{tikz-qtree}
\usetikzlibrary{positioning}
\definecolor{blech}{rgb}{.78,.78.,.62}
\begin{document}
\begin{tikzpicture}
\begin{scope}
  \tikzset{edge from parent/.append style={draw=none}, 
  every tree node/.style={draw=none},level distance=2cm
  }
  \Tree [[.{Level 1} [.{Level 2} ]]]
\end{scope}
  \begin{scope}[xshift=2in]
\tikzset{every tree node/.style={draw,circle, minimum size=2em,fill=blech},
    level distance=2cm,sibling distance=1cm}
    \Tree[.\node (Root) {};
       [.4 11 {} ]
       [.5 6  {} ]
       ]
   \node [above=.25cm of Root] {Root};
\end{scope}
\end{tikzpicture}
\end{document}

output of code

Related Question