Graphviz - how do I make the text in labels left-aligned?

migimunz picture migimunz · Oct 27, 2012 · Viewed 17.7k times · Source

I'm using graphviz to visualize the AST of a language I'm parsing. I want to include the source code (as a label) but graphviz aligns the text inside the label, which messes with my indentation (and code is indentation-sensitive). Here's an example of the problem, the second line of code should not be indented:

enter image description here

This is the relevant part of the generated .dot file:

graph [fontname=Courier,fontsize=10.0,labeljust=l,nojustify=true];
node [shape=box,width=0.2,height=0.2,fontname=Courier,fontsize=10.0,penwidth=0.5];
edge [weight=1.2,penwidth=0.5,fontname=Courier,fontsize=10.0,labeljust=c];
labelloc="t";
label="\ndef square(a, b) -> a * b\ndef dotProduct(a, b) -> \n    a.x * b.x + a.y * b.y\n";

Answer

marapet picture marapet · Oct 28, 2012

You may use \l instead of \n in order to divide the label into left-justified lines.

graphviz label with left-justifed lines