11

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?

0

1 Answer 1

10

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.

0

You must log in to answer this question.

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