Change font size of label of vertex in tkz-graph

fontsizetkz-graph

I am currently writing a tex-file in which I also need to create a graph and label the vertices. I am using the package tkz-graph.

\documentclass{article}
\usepackage{tikz}
\usepackage{tkz-graph}


\begin{document}


\begin{tikzpicture}
 \GraphInit[vstyle=Normal]
    \SetUpEdge
    \SetGraphUnit{1.5}
    \tikzset{VertexStyle/.style = {shape = circle,  minimum size = 30pt, draw}}


    \Vertex[L = a,  x = -2, y = 2]{a}
    \Vertex[L = abcdef,  x = 2, y = 2]{abcdef}

    \Edge[lw=1pt](a)(abcdef)
    
\end{tikzpicture}

\end{document}

The two vertices than appear in different size because the label of the second one is to big and then it automatically increases the size of vertex. I want to change the font size of the label of this vertex but I don't know how and I did not find it in the documentation.
So how do I change the font size of the label of single vertices? If this is not possible how do I change the font size of the labels for all vertices?

Thank you

Best Answer

To set font for all vertices, you can add tikz node options to Vertexstyle, for example \tikzset{VertexStyle/.style={..., font=\large}}.

To set font for a single vertex, you can use \Vertex[..., style={<tikz node options>}] {...}.

Caution: currently local styles (style=...) will be overwritten by the global ones (VertexStyle/.style=...). In the example below, \xpatchcmd from regexpatch is used to change this.

A full list of tikz node font options is documented in pgfmanual v3.1.9a, sec. 17.4.2 "Text Parameters: Font".

\documentclass{article}
\usepackage{tikz} % not necessary because `tikz-graph` will auto load tikz
\usepackage{tkz-graph}

\usepackage{regexpatch}
\makeatletter
\xpatchcmd*{\@@vertex}
  {\cmdGR@vertex@style,\nstyle}
  {\nstyle,\cmdGR@vertex@style}
  {}{\fail}
\makeatother

\begin{document}

\begin{tikzpicture}
 \GraphInit[vstyle=Normal]
    \SetUpEdge
    \SetGraphUnit{1.5}
    \tikzset{VertexStyle/.style = {shape = circle,  minimum size = 30pt, draw, text=blue}}

    % vertex a, "node font=\Large, text=red" (global "text=blue" is overwritten by the local)
    \Vertex[L = a,  x = -2, y = 2, style={node font=\Large, text=red}]{a}
    % vertex b, "text=blue, font=\bfseries"
    \Vertex[L = abcdef,  x = 2, y = 2, style={font=\bfseries}]{abcdef}

    \Edge[lw=1pt](a)(abcdef)
    
\end{tikzpicture}

\end{document}

enter image description here