Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

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

share|improve this answer
    
Can you get the "Root" above the first node? My aim is to reproduce the displayed figure more or less exactly. –  iab Jan 11 at 21:00
    
@iab I've updated my answer. –  Alan Munn Jan 11 at 21:44
    
@Alax Munn Awesome. Thanks :-) –  iab Jan 11 at 22:07
add comment

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

share|improve this answer
1  
You can have the colour until your next name change. :) –  Alan Munn Jan 11 at 22:17
    
@AlanMunn: OK. I will return it tomorrow. :-) –  Fifa Earth Cup 2014 Jan 11 at 22:18
    
@AlanMunn: Your color has been returned. Thanks. –  Fifa Earth Cup 2014 Jan 12 at 17:57
    
You're welcome. :) –  Alan Munn Jan 12 at 18:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.