使用 Graphviz 显示两个相邻的表格,单元格之间有线条

Use Graphviz to show two tables adjacent to each other with lines between cells

我想展示下图,除了两个 table 在同一水平面上。我希望第二个 table 显示在第一个 table 的右侧,而不是像当前那样在其下方。

我目前的 graphviz 代码是:

digraph G  {

   node [shape=record, fontname="Arial"];

   set1 [label = "{Blue Crosses | B1 | B2 | B3 | B4 }|{ Square |<b1>  Left |<b2> Left |<b3> Right | Left }"];
   set2 [label = "{Blue Crosses |<b1> B1 |<b2> B2 |<b3> B3 }|{ Coordinates | (1, 1) | (2, 2) | (4, 2) }"];

  set1:b1 -> set2:b1;
  set1:b2 -> set2:b2;
  set1:b3 -> set2:b3;

}

为了达到你想要的效果,你需要添加行

{ rank = same; set1 set2 }

创建节点后添加到您的代码中。但是,在这种情况下,您会发现 graphviz 变得混乱并且不再识别端口。因此,您需要使用 HTML-like labels 重新编码您的图表,而不是使用 record = shape。对于提供的示例,我已经这样做了(顺便说一下,感谢您对代码和预期结果提出明确的问题):

digraph G  
{
   node[ shape = none, fontname = "Arial" ];

    set1[ label=<
    <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
        <TR>
            <TD>Blue Crosses</TD>
            <TD>Square</TD>
        </TR>
        <TR>
            <TD>B1</TD>
            <TD PORT="b1">Left</TD>
        </TR>
        <TR>
            <TD>B2</TD>
            <TD PORT="b2">Left</TD>
        </TR>
        <TR>
            <TD>Right</TD>
            <TD PORT="b3">Right</TD>
        </TR>
        <TR>
            <TD>B4</TD>
            <TD>Left</TD>
        </TR>
    </TABLE>>];

    set2[ label=<
    <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
        <TR>
            <TD>Blue Crosses</TD>
            <TD>Coordinates</TD>
        </TR>
        <TR>
            <TD PORT="b1">B1</TD>
            <TD>(1, 1)</TD>
        </TR>
        <TR>
            <TD PORT="b2">B2</TD>
            <TD>(2, 2)</TD>
        </TR>
        <TR>
            <TD PORT="b3">B3</TD>
            <TD>(4, 2)</TD>
        </TR>
    </TABLE>>];    

    # layout
    nodesep = 2;                /* increase distance between nodes */
    { rank = same; set1 set2 }

    set1:b1 -> set2:b1;
    set1:b2 -> set2:b2;
    set1:b3 -> set2:b3;
}

产量