[Tex/LaTex] Setting node label’s size and color in TiKZ

labelstikz-styles

I'm drawing AVL trees using the first answer given at AVL Trees in TikZ: draw outside of node as an example.

All I want to do is add a style definition which will draw the labels in a small font and in blue. I can of course do that individually for each label, but it would be more elegant to set it as a style. The style I have so far is

\begin{tikzpicture}[
  level/.style={sibling distance=60mm/#1},
  every node/.style={draw,circle},
  label distance=-1mm]

which works fine – but how do I add blue text and small font size to those labels?

Note that I create each label by its angle and text:

node [label=30:\small $1$] {6}

or for a color

node [label={[blue]30:\small $1$}] {6}

Anyway, I'd like to format the labels as part of the style. Thanks!

Best Answer

There is no problem whatsoever to make the label font blue and small in the answer you are referring to.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[level/.style={sibling distance=60mm/#1},
  every node/.style={draw,circle},
  label distance=-1mm,
   edge from parent path=
    {(\tikzparentnode.south) .. controls +(0,-.5) and +(0,.5)
                             .. (\tikzchildnode.north)},
   every node/.style={draw,circle},
   label distance=-1mm]
\node [label={[font=\small,text=blue]30:$-1$}]{50}
  child {node[label={[font=\small,text=blue]30:$-1$}] {10}}
  child {node[label={[font=\small,text=blue]30:$0$}] {20}
  child {node[label={[font=\small,text=blue]30:$-1$}] {10}}
  child {node[label={[font=\small,text=blue]30:$-1$}] {20}}
};
\end{tikzpicture}
\end{document}

enter image description here

It is easy enough to turn this into a style.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[level/.style={sibling distance=60mm/#1},
  every node/.style={draw,circle},
  label distance=-1mm,
   edge from parent path=
    {(\tikzparentnode.south) .. controls +(0,-.5) and +(0,.5)
                             .. (\tikzchildnode.north)},
   every node/.style={draw,circle},
   label distance=-1mm,
   my label/.style n args={2}{label={[font=\small,text=blue]#1:#2}}]
\node [my label={30}{$-1$}]{50}
  child {node[my label={30}{$-1$}] {10}}
  child {node[my label={30}{$0$}] {20}
  child {node[my label={-30}{$-1$}] {10}}
  child {node[my label={-60}{$-1$}] {20}}
};
\end{tikzpicture}
\end{document}

enter image description here

Related Question