# Cluster alignment with DOT

**URL:** <https://forum.graphviz.org/t/cluster-alignment-with-dot/2704>\
**Category:** Uncategorized\
**Created:** [February 7, 2025, 3:27pm UTC](https://forum.graphviz.org/t/cluster-alignment-with-dot/2704 "2025-02-07T15:27:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fsalvi](https://avatars.discourse-cdn.com/v4/letter/f/ac91a4/32.png) [@Fsalvi](https://forum.graphviz.org/u/Fsalvi)\
**Post date:** [February 7, 2025, 3:27pm UTC](https://forum.graphviz.org/t/cluster-alignment-with-dot/2704/1 "2025-02-07T15:27:58Z")

</div>

[dot verbose=true fit=true]

```auto
digraph G {
		rankdir=TB
		node [fontname="Helvetica,Arial,sans-serif"]
		edge [fontname="Helvetica,Arial,sans-serif"]
		graph [fontsize=30 labelloc="t" label="" splines=false ratio = auto]

	subgraph cluster_left {
		style=filled 
		color="#F4F2EE" 
		fontcolor="black" 
		fontsize=36 
		border=0 
		label = "left side nodes"

		//left side nodes
		left1 -> left2 -> left3 [penwidth=3 color=deeppink style=dotted dir=none] //vertical edge lines will be made invisible
/* as soon as theese lines are uncommented, the clusters become twisted up 
		left1->mainA 
		left2->mainD 
		left3->mainD 
*/
	}

	subgraph cluster_main { 
		style=filled 
		color="#F4F2EE" 
		fontcolor="black" 
		fontsize=36 
		border=0 
		label = "main steps and\nrelated side nodes"

		//main steps
		mainA -> mainB -> mainC -> mainD -> mainE [weight=5]

	} //main cluster end

	subgraph cluster_right {
		style=filled 
		color="#F4F2EE" 
		fontcolor="black" 
		fontsize=36 
		border=0 
		label = "right side nodes"

		//right side nodes
		right1 -> right2 -> right3 -> right4 [penwidth=3 color=deeppink style=dotted dir=none] //vertical edge lines will be made invisible
/* as soon as theese lines are uncommented, the clusters become twisted up 
		right1->mainB 
		right2->mainC 
		right3->mainC 
		right4->mainC 
*/
	}
} //graph end

```

[/dot]

Hello all! I’m trying to achieve what maybe is a simple goal with DOT, but after many attempts using online editors, still cannot do with it.

There is a central cluster of vertical nodes, that acts like a rigid, hard “backbone”, where left and right floating nodes point to.  
My example graph shows the nodes, but as soon as I use {rank=same …} and edges (with constraint=false) for aligning and connecting, clusters gex mixed, nodes migrate in unpredictable ways from one cluster to another, and the whole graph becomes messy.  
What am I doing wrong?  
Many thanks!

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [February 7, 2025, 4:34pm UTC](https://forum.graphviz.org/t/cluster-alignment-with-dot/2704/2 "2025-02-07T16:34:39Z")

</div>

- Not sure why the code displays badly on the web page
- Moved the cross-cluster edges out of the clusters & to the Root graph
- Used **constraint=false** on those edges, to keep the three clusters (reasonably) horizontally aligned

```auto
digraph G {
  rankdir=TB
  node [fontname="Helvetica,Arial,sans-serif"]
  edge [fontname="Helvetica,Arial,sans-serif"]
  graph [fontsize=30 labelloc="t" label="" splines=false ratio = auto]

subgraph cluster_left {
	style=filled 
	color="#F4F2EE" 
	fontcolor="black" 
	fontsize=36 
	border=0 
	label = "left side nodes"
	// left side nodes
	// vertical edge lines will be made invisible
	left1 -> left2 -> left3 [penwidth=3 color=deeppink style=dotted dir=none] 
}

subgraph cluster_main { 
	style=filled 
	color="#F4F2EE" 
	fontcolor="black" 
	fontsize=36 
	border=0 
	label = "main steps and\nrelated side nodes"
	//main steps
	mainA -> mainB -> mainC -> mainD -> mainE [weight=5]
} //main cluster end

subgraph cluster_right {
	style=filled 
	color="#F4F2EE" 
	fontcolor="black" 
	fontsize=36 
	border=0 
	label = "right side nodes"
	//right side nodes
	right1 -> right2 -> right3 -> right4 [penwidth=3 color=deeppink style=dotted dir=none]
}
	edge[constraint=false]
        left1->mainA
        left2->mainD
        left3->mainD
	right1->mainB
	right2->mainC
	right3->mainC
	right4->mainC	
}

```

Giving:

 ![clusterAlignment1](https://global.discourse-cdn.com/graphviz/original/2X/5/5a94acd23e369465cd035a08c5527657840dacef.png)

---

<div class="post-metadata">

**Author:** ![Fsalvi](https://avatars.discourse-cdn.com/v4/letter/f/ac91a4/32.png) [@Fsalvi](https://forum.graphviz.org/u/Fsalvi)\
**Post date:** [February 7, 2025, 4:51pm UTC](https://forum.graphviz.org/t/cluster-alignment-with-dot/2704/3 "2025-02-07T16:51:19Z")

</div>

GREAT! Many many thanks for the answer. Now I will study your solution. Thanks again.

F

---

<div class="post-metadata">

**Author:** ![magjac](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/magjac/32/16_2.png) [@magjac](https://forum.graphviz.org/u/magjac)\
**Post date:** [February 7, 2025, 7:58pm UTC](https://forum.graphviz.org/t/cluster-alignment-with-dot/2704/4 "2025-02-07T19:58:33Z")

</div>

I took the liberty to edit your post slightly in order for the graph to render inline in the forum.

---

<div class="post-metadata">

**Author:** ![Fsalvi](https://avatars.discourse-cdn.com/v4/letter/f/ac91a4/32.png) [@Fsalvi](https://forum.graphviz.org/u/Fsalvi)\
**Post date:** [February 7, 2025, 8:41pm UTC](https://forum.graphviz.org/t/cluster-alignment-with-dot/2704/5 "2025-02-07T20:41:46Z")

</div>

Hello, sure! But it’s due to Steve’s good knowledge, not mine.

---

<div class="post-metadata">

**Author:** ![Fsalvi](https://avatars.discourse-cdn.com/v4/letter/f/ac91a4/32.png) [@Fsalvi](https://forum.graphviz.org/u/Fsalvi)\
**Post date:** [February 8, 2025, 9:36am UTC](https://forum.graphviz.org/t/cluster-alignment-with-dot/2704/6 "2025-02-08T09:36:16Z")

</div>

Hi, maybe this little sample could be useful for others to see in the Gallery. The nodes in the main area would be more meaningful if shaped as boxes.

F
