# Setting node label's size and color in TiKZ?

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!

• Please provide a complete MWE! You have enough experience on this site to do that. BTW, node[label={[font=\small,text=blue]30:$-1$}] {10} should work. – user121799 Oct 12 '18 at 0:48

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}


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}


• Thank you, but I was trying to avoid writing the size and colour in every label, but instead include it as part of the style definition. – Alasdair Oct 12 '18 at 4:07
• Oh now that's fine - thank you! Can you also include the degree as a parameter to "my label"? - sometimes a label at 30 degrees (in my tree which has straight edges) will be written over an edge. – Alasdair Oct 12 '18 at 9:22
• @Alasdair Done. – user121799 Oct 12 '18 at 13:31
• Perfect! The "n args" is new to me. Thank you very much indeed! – Alasdair Oct 12 '18 at 19:58