1

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

2
  • Welcome to TeX.SE! Can you please make your code snippet be compilable? Then we do not have to guess what you are doing ...
    – Mensch
    Nov 18, 2021 at 16:27
  • Hi, thank you for your reply. Is it now better?
    – amhineoni
    Nov 18, 2021 at 16:39

1 Answer 1

2

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

4
  • you can also use several \tikzset{VertexStyle/.style ... Nov 18, 2021 at 22:24
  • @AlainMatthes Hi Alain, to the option precedence issue I've opened github.com/tkz-sty/tkz-graph/issues/1 under which David Carlisle questioned if that repo should be archived. Nov 18, 2021 at 22:42
  • I'm not a great expert in using GitHub but you are right it would be better to reverse the styles. Nov 19, 2021 at 5:40
  • 1
    I will make an update in the next days. Nov 19, 2021 at 6:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .