# Aligning these 2 subgraphs horizontally?

**URL:** https://forum.graphviz.org/t/aligning-these-2-subgraphs-horizontally/3253
**Category:** Help
**Created:** [January 3, 2026, 6:35pm UTC](https://forum.graphviz.org/t/aligning-these-2-subgraphs-horizontally/3253 "2026-01-03T18:35:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![keyko](https://avatars.discourse-cdn.com/v4/letter/k/a8b319/32.png) [@keyko](https://forum.graphviz.org/u/keyko)
#### Post date: [January 3, 2026, 6:35pm UTC](https://forum.graphviz.org/t/aligning-these-2-subgraphs-horizontally/3253/1 "2026-01-03T18:35:26Z")

</div>

I’ve been trying get two graphs aligned. I did check this [post](https://forum.graphviz.org/t/subgraph-rank-alignment-edited/1604).

This is the code I’ve played with:

```dot
digraph {
    graph [
     nodesep=1,
     ranksep=0.9, 
     compound=true,
     newrank=true
    ];
    rankdir=LR;
    node [shape=record, fontname="Helvetica"];

    subgraph cluster_dev1 {
        label="Device 1";
        style=rounded;
        color=gray50;
        margin=12;
        struct1 [
            label="<port1>Tx|<port2>Rx";
        ];
    }

    subgraph cluster_dev2 {
        label="Device 2";
        style=rounded;
        color=gray50;
        margin=12;
        struct2 [
            label="<port1>Tx|<port2>Rx";
        ];
    }
    struct1:port1 -> struct2:port2;
    struct2:port1 -> struct1:port2;
    {rank=same struct1 struct2 }
}

```

And here [is a demo](https://magjac.com/graphviz-visual-editor/?dot=digraph%20%7B%0A%20%20%20%20graph%20%5B%0A%20%20%20%20%20nodesep%3D1%2C%0A%20%20%20%20%20ranksep%3D0.9%2C%20%0A%20%20%20%20%20compound%3Dtrue%2C%0A%20%20%20%20%20newrank%3Dtrue%0A%20%20%20%20%5D%3B%0A%20%20%20%20rankdir%3DLR%3B%0A%20%20%20%20node%20%5Bshape%3Drecord%2C%20fontname%3D%22Helvetica%22%5D%3B%0A%0A%20%20%20%20subgraph%20cluster_dev1%20%7B%0A%20%20%20%20%20%20%20%20label%3D%22Device%201%22%3B%0A%20%20%20%20%20%20%20%20style%3Drounded%3B%0A%20%20%20%20%20%20%20%20color%3Dgray50%3B%0A%20%20%20%20%20%20%20%20margin%3D12%3B%0A%20%20%20%20%20%20%20%20struct1%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22%3Cport1%3ETx%7C%3Cport2%3ERx%22%3B%0A%20%20%20%20%20%20%20%20%5D%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20subgraph%20cluster_dev2%20%7B%0A%20%20%20%20%20%20%20%20label%3D%22Device%202%22%3B%0A%20%20%20%20%20%20%20%20style%3Drounded%3B%0A%20%20%20%20%20%20%20%20color%3Dgray50%3B%0A%20%20%20%20%20%20%20%20margin%3D12%3B%0A%20%20%20%20%20%20%20%20struct2%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22%3Cport1%3ETx%7C%3Cport2%3ERx%22%3B%0A%20%20%20%20%20%20%20%20%5D%3B%0A%20%20%20%20%7D%0A%20%20%20%20struct1%3Aport1%20-%3E%20struct2%3Aport2%3B%0A%20%20%20%20struct2%3Aport1%20-%3E%20struct1%3Aport2%3B%0A%0A%7D%0A)

Any help? I want the subgraphs at the same distance from the top margin / horizontally aligned.

---

<div class="post-metadata">

### Author: ![keyko](https://avatars.discourse-cdn.com/v4/letter/k/a8b319/32.png) [@keyko](https://forum.graphviz.org/u/keyko)
#### Post date: [January 3, 2026, 7:16pm UTC](https://forum.graphviz.org/t/aligning-these-2-subgraphs-horizontally/3253/2 "2026-01-03T19:16:39Z")

</div>

Manage to do it using a different syntax:

```auto
digraph {
	fontname="Helvetica,Arial,sans-serif"
    graph [
     nodesep=1,
     ranksep=0.9, 
     compound=true,
     newrank=true
    ];
    rankdir=TB;
    node [shape=record fontname="Helvetica,Arial,sans-serif" style="filled" fillcolor="lightblue"];

    subgraph cluster_dev1 {
        label="UART 1";
        style="rounded,filled";
        fillcolor=gray90;
        margin=12;
        
        Tx1
        Rx1
    }

    subgraph cluster_dev2 {
        label="UART 2";
        style="rounded,filled";
        fillcolor=gray90;
        margin=12;
        Tx2
        Rx2
    }

    Tx1 -> Rx2
    Tx2 -> Rx1;
}

```

Renders to

 ![Untitled Graph 2](https://global.discourse-cdn.com/graphviz/original/2X/5/56663e3c5f87824948ca7c9939b153d5f6f8dd23.svg)
