In graphviz, can you bring two vertices closer together?

167 Views Asked by At

When describing a graph with graphviz, I sometimes find I want two vertices to appear closer together than the layout engine I chose places them. Is there a way to hint that I want them closer?

I'm mostly interested in the case of two connected vertices, so an answer specific to that case is fine.


Concrete example:

digraph G {
  node [shape="circle"];
  Start [shape="none" label=""];
  C [shape="doublecircle"];
  Start -> A;
  A -> B [label="0,1"];
  B -> C [label="0,1"];
  C -> D [label="0,1"];
  D -> D [label="0,1"];
}

enter image description here I want the vertices Start and A to be closer.

2

There are 2 best solutions below

1
Jens On

You can't do that, but you can make nearly everything else twice as big, here is a start. (But you can't increase the size of an edge to self)

digraph G {
  rankdir=LR
  edge[minlen=2 fontsize=28 arrowsize=2 penwidth=2]
  node[fontsize=28 height=1 penwidth=2]
  graph[fontsize=28 penwidth=2]
  node [shape="circle"];
  Start [shape="none" label=""];
  C [shape="doublecircle"];
  Start -> A[minlen=1]; // not twice the size to get the requested effect
  A -> B [label="0,1"];
  B -> C [label="0,1"];
  C -> D [label="0,1"];
  D -> D [label="0,1"];
}

enter image description here

1
sroush On

[this answer applies specifically to dot]

  • there is no edge-level attribute that explicitly sets or changes edge length
  • the graph-level nodesep attribute sets minimum distance between two nodes of same rank

so:

digraph G {
  nodesep=.17
  {
  rank=same
  node [shape="circle"];
  Start [shape="none" label=""];
  C [shape="doublecircle"];
  Start -> A;
  A -> B [label="0,1"];
  B -> C [label="0,1"];
  C -> D [label="0,1"];
  D -> D [label="0,1"];
  }
}

produces:
enter image description here

To increase the distance between the other nodes, you can add spaces to the labels.

I'm not wild about it either, but this change:

  B -> C [label="       0,1       "]; // pad to make label (and edge) longer

produced this:
enter image description here