Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

graphviz

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"; 
like image 611
migimunz Avatar asked Oct 27 '12 19:10

migimunz


People also ask

How do I align text in a label?

We specify the margin-bottom of our <div> element. Then, we set the display of the <label> element to "inline-block" and give a fixed width. After that, set the text-align property to "right", and the labels will be aligned with the inputs on the right side.

Should text be left aligned or centered?

Centered headlines should go with centered text. Left aligned headlines should go with left aligned text. Avoid mixing the two together so that your text doesn't look unbalanced. Following these guidelines will help make your text look appealing and easy to read.


1 Answers

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

graphviz label with left-justifed lines

like image 180
marapet Avatar answered Oct 14 '22 01:10

marapet