Graphviz: how to reduce the top and bottom margins of a node?
digraph { rankdir = LR
node [shape=box margin=0 width=0 height=0]
asdf [label="asdf\nasdf"]
qwer [label="qwerqwer"]
asdf -> qwer
}
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"
}
Smaller:
digraph {
node [shape=box,width=0.1,height=0.1]
a -> "longer name"
"longer name" -> "taller\nname"
}
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"
}