Search code examples
graphviz

Graphviz vertical align subgraph with node while using left to right


I am trying to create a subgraph that is below the MEMOR node using Graphviz and I am struggling to get them lined up correctly,

This is what I have tried so far: enter image description here I want to get the ST boxes to be below MEMOR and reading to be the furthest to the right.

Digraph {
  layout = dot
  rankdir=LR;

ESCS[shape = box]

Gender[label = "Gender \n (female)", shape = box]


{ESCS, Gender} -> MEMOR


MEMOR -> {ST27Q01,ST27Q03, ST27Q05, ST27Q07}
subgraph cluster0 {
    style=invis;
    ST27Q01,ST27Q03, ST27Q05, ST27Q07[shape = box]
    ST27Q01 -> ST27Q03 -> ST27Q05 -> ST27Q07 [style = "invis"]
}

READING[shape = box, rank = "max"]
MEMOR -> READING

}

The end result being something like this enter image description here


Solution

  • Does this work (with some tweaking)?

    Digraph {
      layout = dot
      rankdir=LR;
      splines=false  // added
    
    ESCS[shape = box]
    
    Gender[label = "Gender \n (female)", shape = box]
    
    
    {ESCS, Gender} -> MEMOR
    
    subgraph clusterA{
      peripheries=0
       {rank=same
       MEMOR
       tbl1 [shape=none label=<<table border="0" cellborder="1"><tr><td port="p1">ST27Q01</td><td port="p2">ST27Q03</td><td port="p3">ST27Q05</td><td port="p4">ST27Q0</td></tr></table>>]
        tbl1 -> MEMOR [style=invis]  // kludge to put memor above table
        edge [constraint=false]      // more of same kludge to put memor above table  
        MEMOR ->  tbl1:p1
        MEMOR ->  tbl1:p2
        MEMOR ->  tbl1:p3
        MEMOR ->  tbl1:p4
        }
    }
    subgraph clusterB{
      peripheries=0
       {rank=same
       ELAB
       tbl2 [shape=none label=<<table border="0" cellborder="1"><tr><td port="p1">ST27Q01</td><td port="p2">ST27Q03</td><td port="p3">ST27Q05</td><td port="p4">ST27Q0</td></tr></table>>]
        tbl2 -> ELAB [style=invis]  // kludge to put elab above table
        edge [constraint=false]      // more of same kludge to put elab above table  
        ELAB ->  tbl2:p1
        ELAB ->  tbl2:p2
        ELAB ->  tbl2:p3
        ELAB ->  tbl2:p4
        }
    }
    
    READING[shape = box, rank = "max"]
    { MEMOR ELAB } -> READING
    
    }
    

    Giving:
    enter image description here