8

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.

2 Answers 2

7

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

2
  • Can you get the "Root" above the first node? My aim is to reproduce the displayed figure more or less exactly.
    – picasso
    Jan 11, 2014 at 21:00
  • @iab I've updated my answer.
    – Alan Munn
    Jan 11, 2014 at 21:44
3

A recommended solution with PSTricks.

\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{pst-tree}
\definecolor{mycolor}{RGB}{199 199 158}% my own color 

\psset{radius=10pt,fillstyle=solid,fillcolor=mycolor}

\begin{document}
\psTree[thislevelsep=0]{\Tn}
    \psTree{\Tn}
        \psTree[edge=none]{\Tr{Level 1}}
                \Tr{Level 2}
        \endpsTree
    \endpsTree
    \psTree{\TCircle{}~[tnpos=a]{Root}}
        \psTree{\TCircle{4}}
                \TCircle{11}
                \TCircle{}
        \endpsTree
        \psTree{\TCircle{5}}
                \TCircle{6}
                \TCircle{}
        \endpsTree
    \endpsTree
\endpsTree
\end{document}

enter image description here

3
  • 1
    You can have the colour until your next name change. :)
    – Alan Munn
    Jan 11, 2014 at 22:17
  • @AlanMunn: OK. I will return it tomorrow. :-) Jan 11, 2014 at 22:18
  • @AlanMunn: Your color has been returned. Thanks. Jan 12, 2014 at 17:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .