graphvizdot

Move 2 nodes to the side without affecting the rest of the layout


I have the following dot layout:

digraph {
  a b c

  a -> b b -> c

  b -> g1 [dir=back,constraint=false]
  b -> g2 [dir=back,constraint=false]

  g1 -> g2 [style=invis]
}

result of the dot layout above

I would like g1 and g2 to be closer to each other and vertically centered around b like this:

what I want instead

I tried with a subgraph and cluster for g1 and g2 and with some invisible edges. I never managed to do anything good enough.


Solution

  • The easiest way is to set rankdir=LR to make node alignment vertical instead of horizontal. Then use rank=same to keep a, b, and c aligned.

    digraph {
      rankdir=LR  // now alignment is vertical
    
      {rank=same
        a b c
      }
      a -> b
      b -> c
    
      b -> g1 [dir=back] 
      b -> g2 [dir=back] 
    }
    

    Giving:
    enter image description here