Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz: how to reduce the top and bottom margins of a node?

Tags:

graphviz

How can I reduce the top and bottom margins of these Graphviz nodes? I am specifying "0.05, 0.0 as the margins to each node, with fontsize = 8.

like image 734
LKramer Avatar asked Apr 09 '15 12:04

LKramer


2 Answers

digraph { rankdir = LR
    node [shape=box margin=0 width=0 height=0]
    asdf [label="asdf\nasdf"]
    qwer [label="qwerqwer"]
    asdf -> qwer
}
like image 131
stefan Avatar answered Oct 05 '22 20:10

stefan


Nodes have a default minimum size (width and height), so if you reduce margins beyond a certain point, it has no effect. At least, this is how it works with box (rectangular) nodes and some of the other simple shapes.

width and height actually specify the minimum width and height, not the actual width and height (unless you also specify that sizes are fixed). So to get smaller margins, you can just use very small width and height values, and the shapes will still be stretched to fit the labels.

With defaults:

digraph {
    node [shape=box]
    a -> "longer name"
    "longer name" -> "taller\nname"
}

enter image description here

Smaller:

digraph {
    node [shape=box,width=0.1,height=0.1]
    a -> "longer name"
    "longer name" -> "taller\nname"
}

enter image description here

You can also set the margin itself if you want it smaller:

digraph {
    node [shape=box,width=0.1,height=0.1,margin=0.01]
    a -> "longer name"
    "longer name" -> "taller\nname"
}

enter image description here

like image 21
aldel Avatar answered Oct 05 '22 19:10

aldel