1

I've written the following graphviz code to draw a crown graph on 8 nodes:

graph G {
  u1 [label=<<I>u<SUB>1</SUB></I>>]
  v1 [label=<<I>v<SUB>1</SUB></I>>]
  u2 [label=<<I>u<SUB>2</SUB></I>>]
  v2 [label=<<I>v<SUB>2</SUB></I>>]
  u3 [label=<<I>u<SUB>3</SUB></I>>]
  v3 [label=<<I>v<SUB>3</SUB></I>>]
  u4 [label=<<I>u<SUB>4</SUB></I>>]
  v4 [label=<<I>v<SUB>4</SUB></I>>]
  u1 -- v2 
  u1 -- v3 
  u1 -- v4
  u2 -- v1
  u2 -- v3
  u2 -- v4
  u3 -- v1
  u3 -- v2
  u3 -- v4
  u4 -- v1
  u4 -- v2
  u4 -- v3
}

The result when compiled with dot is good, but not quite what I want - I need the order of the top 'layer' of nodes to be u_1, u_2, u_3, u_4, and the bottom layer to be v_1, v_2, v_3, v_4, so that it can look like a crown graph. However, I'm not sure how to tell dot to do this. Any help would be awesome.

Koz Ross
  • 3,040
  • 2
  • 24
  • 44

1 Answers1

3

Some useful techniques to control the layout of nodes include:

Most useful when combined.

In this particular case, you may apply constraint=false on your edges in order to not have them influence the layout, and add invisible edges to position the nodes.

Insert the following bit between your node declarations and the edge list (after line 9):

  edge[style=invis]
  u1 -- v1
  u2 -- v2
  u3 -- v3
  u4 -- v4
  edge[style=visible, constraint=false]
Community
  • 1
  • 1
marapet
  • 54,856
  • 12
  • 170
  • 184