19

Is there any way to get graphviz to left-align or right-align nodes in the same rank, instead of centering?

alt text

   digraph h {
     rankdir=LR;

     node [shape=record,height=.08,fontsize=11];

     elk[label="elk|I am an American Elk"];

     buffalo[label="buffalo|Just a buffalo|everywhere I go|people know the part I'm playing"];

     cow[label="cow|moo"];

     moose[label="Bullwinkle J. Moose|Hey Rocky, watch me pull a rabbit out of my hat!"];

     zoo [label="zoo|<p0>|<p1>|<p2>|<p3>"];

     zoo:p0 -> elk;
     zoo:p1 -> cow;
     zoo:p2 -> moose;
     zoo:p3 -> buffalo;
   }
Community
  • 1
  • 1
Jason S
  • 184,598
  • 164
  • 608
  • 970

2 Answers2

27

It's nice to see someone working with such weighty data.

Here's one kludgey and unsatisfying way:

digraph h {
     rankdir=LR;
     node [shape=record,height=.08,fontsize=11];
     zoo [label="zoo|<p0>|<p1>|<p2>|<p3>"];

     node [width=3.5];
     elk[label="elk\l|I am an American Elk\l",];
     buffalo[label="buffalo\l|Just a buffalo\l|everywhere I go\l|people know the part I'm playing\l"];
     cow[label="cow\l|moo\l"];
     moose[label="Bullwinkle J. Moose\l|Hey Rocky, watch me pull a rabbit out of my hat!\l"];

     zoo:p0->elk; zoo:p1 -> cow; zoo:p2 -> moose; zoo:p3 -> buffalo;
}

Give each box in that rank the same (empirically determined) width, then left-align the text using the weird \l "left-aligned linebreak".

Jonathan Feinberg
  • 44,698
  • 7
  • 80
  • 103
  • 6
    Hmm. I don't need the *text* left-aligned in the node (centering is fine), I just want the nodes left-aligned, & don't like constant width. – Jason S Jan 21 '10 at 19:55
  • The reason is because a node position in a graph is in all situation calculated by it's center. The dimension of it's labels are also dependend on non-graph attributes like font-with and/or font-family. Nothing what a direct graph calculation is aware of. – CodeFreezr Mar 12 '18 at 00:25
1

Answered here: Top-align nodes

Adding node[rankjustify=min] before "zoo" and following the instructions pointed to above will give:
enter image description here

sroush
  • 5,375
  • 2
  • 5
  • 11