I created a Binary Tree. This is my code:

\begin{tikzpicture}[level/.style={sibling distance=80mm/#1}]
    child {node [circle,draw] {$30$}
        child {node [circle,draw] {$10$}
            child {node [circle,draw] {$20$}}}
        child {node [circle,draw] {$40$}}}
    child {node [circle,draw] {$80$}
        child {node [circle,draw] {$60$}
            child{node [circle,draw] {$70$}}}
        child {node [circle,draw] {$90$}
            child{node [circle,draw] {$85$}}
            child{node [circle,draw] {$95$}}}};

How can I add small numbers next to the nodes, like here?

enter image description here

Thank you.

  • What does \cm mean in your code? Please give complete minimum working example.
    – ZhiyuanLck
    Jun 13, 2020 at 14:02
  • Oh sorry, it means it means that i Insert a missing child
    – Joshua
    Jun 13, 2020 at 14:11

1 Answer 1


I do not know the definition of \cm in your code, so I remove it. You can use label to place another node around original node. See pgfmanual sec 17.10.2 The Label Option.

\documentclass[tikz, border=1cm]{standalone}

\begin{tikzpicture}[level/.style={sibling distance=80mm/#1}]
    child {node [circle,draw,label={[green]above left:{5}}] {$30$}
        child {node [circle,draw,label={[green]above left:{5}}] {$10$}
            child {node [circle,draw,label={[green]above left:{5}}] {$20$}}}
        child {node [circle,draw,label={[teal]right:{5}}] {$40$}}}
    child {node [circle,draw,label={[orange]above right:{6}}] {$80$}
        child {node [circle,draw,label={[green]above left:{5}}] {$60$}
            child{node [circle,draw,label={[green]above left:{5}}] {$70$}}}
        child {node [circle,draw,label={[draw,rotate=45,orange, anchor=west]above right:{test code}}] {$90$}
            child{node [circle,draw,label={[green]above left:{5}}] {$85$}}
            child{node [circle,draw,label={[green]right:{5}}] {$95$}}}};

enter image description here

  • Yes, thats it. Thank you very much.
    – Joshua
    Jun 13, 2020 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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