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 trying to draw AVL trees with TikZ, what I need is:

Binary tree with simple circle nodes, and adjustable height triangle (or rectangle) nodes for subtrees, both containing only single characters. Here's a picture:

enter image description here

I tried with rectangle and regular polygon, but they seem to be unaffected by aspect ratio... Is there an easy way of drawing something like this in TikZ?

share|improve this question

1 Answer 1

up vote 9 down vote accepted

Using the isosceles triangle shape and some manually set heights:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}[
  inner/.style={circle,draw,minimum width=7mm,inner sep=0},
  leaf/.style={isosceles triangle,draw,shape border rotate=90,isosceles triangle stretches=true, minimum height=20mm,minimum width=12mm,inner sep=0,yshift={-20mm},font=\tiny},
  large leaf/.style={leaf,minimum height=35mm,yshift={-14.5mm}},
  level 1/.style={sibling distance=30mm},
  level 2/.style={sibling distance=21mm},
  level 3/.style={sibling distance=14mm},
]
  \node[inner] {T}
    [child anchor=north]
    child {node[inner] {L}
      child {node[large leaf] {}}
      child {node[inner] {LR}
        child{node[leaf] {}}
        child{node[leaf] {}}}}
    child {node[large leaf] {L.Allison}};
\end{tikzpicture}

\end{document}

result

I don't know why the top vertices of the two large triangles are at different heights relative to their sibling nodes.

share|improve this answer
    
Thank you very much :) –  tpv Dec 28 '10 at 18:06

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.