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

Graphviz

Graphviz Problem Overview


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";

Graphviz Solutions


Solution 1 - Graphviz

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

graphviz label with left-justifed lines

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmigimunzView Question on Stackoverflow
Solution 1 - GraphvizmarapetView Answer on Stackoverflow