Cluster label is cut off when rendering with SVG

The following dot code:

strict digraph cluster {
	graph [
	subgraph "cluster_foo" {
		graph [
		"bar"		 [fillcolor=forestgreen,

renders the following image (dot -Tsvg d -o foo.svg):

Does anyone know why the “s” is cut off and how I can fix it?

[Font problems are enough to drive people crazy, let’s hope that does not happen here]
[Note, I am not encountering the problem of the cluster being to narrow. If anything, I am seeing cluster-too-wide.]
The Font FAQ (Font FAQ | Graphviz) will tell you lots about font problems.
Here are some possible solutions to this specific problem - choose one:

  • use dot -Tsvg:cairo (Font FAQ | Graphviz)
  • remove style=bold, It seems redundant with <B>
  • use
    fontname="Times-Bold" label="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrs"
    instead of
  • add spaces to the end of your label text

Good luck

Thank you for the fast reply!

style=bold is not redundant, as this attribute is referring to the bounding box, not the font. Additionally, I only want part of the label to be bold, as I plan on adding additional detail to the label later.

I’ve confirmed that using svg:cairo fixes the issue, however I am not certain the extra overhead is worth it. Therefore, I think the only option left is for me to add additional spaces.

As Steve has alluded to, the problem is essentially that Graphviz’ native SVG renderer only does a limited estimation of text width. Answering “how wide is this text?” is a surprisingly complicated question. A full solution looks something like Cairo, which is why Graphviz has support for using that.

If you want to stick to using the core rendered but want more accurate estimations, the code that does it is here and we welcome improvements: lib/common/textspan_lut.c · main · graphviz / graphviz · GitLab

1 Like

Yes, this is good advice. Also, a start would be to confirm that Graphviz and the final renderer are loading the same font file. Graphviz prints the font binding when run with -v