title: How to align subgraphs in dot files
body: <p>I am trying to align three or more subgraphs using dot files and graphviz. I think my problem is best shown using a few examples:</p>
  <p>My first try:</p>
  <pre><code>digraph FutopJobFlow {
      rankdir=LR;
      node [shape=box]
      compound=true
  
      subgraph clusterA {label = &quot; A &quot;;
          A -&gt; a1;
          a1 -&gt; a2;
          a2 -&gt; a3;
      }
  
      subgraph clusterB {label = &quot; B &quot;;
          B -&gt; b1;
          b1 -&gt; b2;
      }
  
      subgraph clusterC {label = &quot; C &quot;;
          C -&gt; c1;
          c1 -&gt; c2;
      }
      A -&gt; B [lhead=clusterB];
      B -&gt; C [lhead=clusterC];
      X -&gt; A [lhead=clusterA];
      Y -&gt; B [lhead=clusterB];
      Z -&gt; C [lhead=clusterC];
  }
  </code></pre>
  <p>giving this result:</p>
  <p><img src="https://i.stack.imgur.com/Qpv5A.jpg" alt="First try of aligning subgraphs" /></p>
  <p>Here the individual subgraphs looks like i would like but the are not aligned. I therefore tried wit the command rank:</p>
  <pre><code>digraph FutopJobFlow {
      rankdir=LR;
      node [shape=box]
      compound=true
  
      subgraph clusterA {label = &quot; A &quot;;
          A -&gt; a1;
          a1 -&gt; a2;
          a2 -&gt; a3;
      }
  
      subgraph clusterB {label = &quot; B &quot;;
          B -&gt; b1;
          b1 -&gt; b2;
      }
  
      subgraph clusterC {label = &quot; C &quot;;
          C -&gt; c1;
          c1 -&gt; c2;
      }
  
      {rank=same; A; B; C;}
  
      A -&gt; B [lhead=clusterB];
      B -&gt; C [lhead=clusterC];
      X -&gt; A [lhead=clusterA];
      Y -&gt; B [lhead=clusterB];
      Z -&gt; C [lhead=clusterC];
  }
  </code></pre>
  <p>which result in this graph:
  <img src="https://i.stack.imgur.com/yfjyg.jpg" alt="Second try of aligning subgraphs" /></p>
  <p>Here the alignment looks good but now the 'A', 'B' and 'C' is no longer inside the subgraphs!</p>
  <p>I have tried several other ways to achieve both the alignment and that 'A', 'B' and 'C' is inside their respective subgraphs but with no succes.</p>
  <p>Can anybody help?</p>
  <p>@ Marapet - Thanks it is almost perfect now - it looks like this when i add the 'constraint=false' parameter:</p>
  <p><a href="https://i.stack.imgur.com/lMZJI.jpg" rel="nofollow noreferrer">Graph with constraint parameter</a></p>
  <p>It would be perfect if the subgraph 'A' is above 'B' which again is above 'C'.</p>