Search code examples
graphvizdot

Change distance between edges in dot


Is there a way to control the spacing between edges in dot, similar to the nodesep attribute in the other graphviz layout engines? I would like to keep using dot as the layout engine.

By edges I mean either multi-edges or multi-coloured edges, like in the following example. I would like to decrease the space between the a->b edges or increase the space between the c->d edges.

digraph G {
  nodesep = "0.15"
  a -> b [dir=none color="red"]
  a -> b [dir=none color="blue"]
  a -> b [dir=none color="green"]
  
  c -> d [dir=none color="green:red:blue"]
}

graph

In dot, the nodesep attribute does not have the desired effect.


Solution

  • The best solution I've found is to add transparent edges. That way, this solution works regardless of background colour. Since the edges are transparent, overlap is not a problem and all the coloured edges have the same width.

    digraph G {
      c -> d [
        dir=none
        penwidth=5
        color="red:transparent:transparent:green:transparent:transparent:blue"
      ]
    }
    

    Produces:

    graph

    This works for an arbitrary number of edges, and the spacing can be controlled by changing the number of transparent edges between each coloured edge.