Sorry, one rankdir per graph.
Suggestions - from simplest to hardest:
- Do not mix “horizontal” and “vertical” nodes in one graph. You could create multiple graphs and then use gvpack (https://www.graphviz.org/pdf/gvpack.1.pdf) to glue them together.
- Do not mix “horizontal” and “vertical” nodes on the same rank
- Alter node placement to “top-of-rank” or “bottom-of-rank” (see reposition nodes within a rank (dot / Graphviz) · GitHub)
- Try osage (osage | Graphviz and Top Rank Node is not center aligned over some subgraphs - #4 by steveroush)
- DIY node placement from scratch. Doable, but why in this case?
Here are two graphs in one file (dot -O …) that created two output files that were then glued together with gvpack
// changed to HTML-like labels,
// used sides to define out-of-bounds, colors to help location, and compass ports
// stopped using cluster for array1
//
// write postscript or use dot ... -O
// horizontal graphs
digraph H {
rankdir=BT; // note! BT
array1 [shape=plain label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="6">
<tr><td colspan="6" sides="b" >int_array</td></tr>
<tr>
<td port="before" sides="r" bgcolor="lightpink"> </td>
<td port="0">5</td>
<td port="1">4</td>
<td port="2">1</td>
<td port="3">3</td>
<td port="4">2</td>
<td port="after" sides="l" bgcolor="lightpink"> </td>
</tr></table>> ];
array1_i [label="i=1"];
array1_j [label="j=-1"];
array1_i -> array1:1
array1_j -> array1:before;
}
// vertical graphs
digraph V {
rankdir=LR;
array2 [shape=plain label=<
<table border="0" cellborder="1" cellspacing="0" cellpadding="6">
<tr><td colspan="1" sides="b" >str_array</td></tr>
<tr><td port="before" sides="b" bgcolor="lightpink"> </td></tr>
<tr><td port="0">abc</td></tr>
<tr><td port="1">def</td></tr>
<tr><td port="2">ghi</td></tr>
<tr><td port="3">jhl</td></tr>
<tr><td port="4">mno</td></tr>
<tr><td port="after" sides="t" bgcolor="lightpink"> </td></tr>
</table>> ];
array2_p [label="p=-1"];
array2_q [label="q=1"];
## added compass ports
array2:1:e -> array2_q [dir=back]
array2_p -> array2:before:w
}
Giving: