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 an AVL tree with TikZ. I got the basic tree structure covered, but I'm not sure how to draw the balance factor outside of the node (see picture below).

Any suggestions?

enter image description here

share|improve this question

1 Answer 1

up vote 6 down vote accepted

One option is to add labels to the nodes in the tree, e.g.


   edge from parent path=
    {(\tikzparentnode.south) .. controls +(0,-.5) and +(0,.5)
                             .. (\tikzchildnode.north)},
   every node/.style={draw,circle},
   label distance=-1mm]
\node [label=330:$-1$]{50}
  child {node[label=330:$-1$] {10}}
  child {node[label=330:$0$] {20}
  child {node[label=330:$-1$] {10}}
  child {node[label=330:$-1$] {20}}

enter image description here

share|improve this answer
This works great. I didn't even know about this feature at all. Thanks for pointing it out. –  hauptbenutzer May 6 '12 at 1:03
@hauptbenutzer No problem. For reference, it's described in section 16.10 The Label and Pin Options of the manual. –  Torbjørn T. May 6 '12 at 1:22

Your Answer


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.