# Dot more layout control

**URL:** <https://forum.graphviz.org/t/dot-more-layout-control/586>\
**Category:** Help\
**Created:** [March 29, 2021, 6:06pm UTC](https://forum.graphviz.org/t/dot-more-layout-control/586 "2021-03-29T18:06:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivo](https://avatars.discourse-cdn.com/v4/letter/i/ee7513/32.png) [@ivo](https://forum.graphviz.org/u/ivo)\
**Post date:** [March 29, 2021, 6:06pm UTC](https://forum.graphviz.org/t/dot-more-layout-control/586/1 "2021-03-29T18:06:33Z")

</div>

I know dot is not primarily a typesetting layout package, but I like it for the nice language and the nice drawings for some diagrams. I want to have better layout control. I understand rank=same, and it is very helpful, but I do not just want row control or column control (depending on rankdir), I really want more of both.

right now, I am struggling how to convince a basic tree diagram in LR rankdir to flip parts of the graph.

![grok](https://global.discourse-cdn.com/graphviz/original/1X/be45a53a79ddf1a944dc51914ad31ae6847e5eaf.jpeg)

I am using C for column and R for row. I want to flip C2 and C3 not to go from bottom to top, but from top-to-bottom. the code I have been using is

```
digraph G {
	rankdir="LR";

	boxme [shape="box"]

	start -> C1R1 ;
	start -> C1R2 ;

	C1R1 -> boxme ;
	C1R1 -> C2R1 ;

	boxme -> C2R2 ;
	boxme -> C2R3 ;

	subgraph cluster_0 {
		label= "surrounded";
		color=blue;
		style=rounded; style=dashed; ## only last one takes
		node [style=filled, color=green];
		C3R1 -> C3R2 -> C3R3 -> C3R4 [style=invis];
		{ rank = same; C3R1; C3R2; C3R3; C3R4; };
	}

	C2R1 -> C3R1 ;
	C2R1 -> C3R2 ;

	C2R2 -> C3R3 ;
	C2R2 -> C3R4 ;

	C2R3 -> C3R5 ;
	C2R3 -> C3R6 ;

	{ rank = same; C1R1; C1R2; }
	{ rank = same; C2R1; C2R2; C2R3; }

# why does the following remove the surrounded box? (and algorithm crosses arrows)
#	{ rank = same; C3R1; C3R2; C3R3; C3R4; C3R5; C3R6; }
}

```

there is also the very strange layout (needlessly crossing arrows) when I uncomment out the final statement, and the dotted box no longer works.

by trial and error, I have figured out that the order in which statements appear can sometimes change the internaly dot layout algorithm, but I don’t understand how this works, either.

is dot entirely the wrong tool for what I want to do? or can it be coaxed appropriately with more layout control?

advice appreciated.

/iaw

---

<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:** [March 29, 2021, 11:06pm UTC](https://forum.graphviz.org/t/dot-more-layout-control/586/2 "2021-03-29T23:06:35Z")

</div>

1. Attribute declarations are not additive, they replace earlier definitions. You want **style=“rounded,dashed”**

2. To try to keep nodes in the sequence you want, use something like this (invisible edges):  
`{ rank = same; C3R1 -> C3R2 -> C3R3 -> C3R4 [style=invis] };`

3. The underlying problem with the last rank (column) is a bug in **dot** related to **rankdir=LR** ([setting rankdir causes odd node ordering (#1953) · Issues · graphviz / graphviz · GitLab](https://gitlab.com/graphviz/graphviz/-/issues/1953))  
Here is your graph tweaked. Correct w/ std rankdir, funky result w/ rankdir=LR:

 ![formattingAgain2.good](https://global.discourse-cdn.com/graphviz/original/1X/fecab8c0ce152ad408900168fdffe6ae31753f75.png)  
 ![formattingAgain2.bad](https://global.discourse-cdn.com/graphviz/original/1X/9de3ae9372742a5315817cd24e5c0106335ff8e6.png)

---

<div class="post-metadata">

**Author:** ![ivo](https://avatars.discourse-cdn.com/v4/letter/i/ee7513/32.png) [@ivo](https://forum.graphviz.org/u/ivo)\
**Post date:** [March 30, 2021, 12:44am UTC](https://forum.graphviz.org/t/dot-more-layout-control/586/3 "2021-03-30T00:44:31Z")

</div>

thank you. very kind of you. this case seems even worse than the specific bug, with crossing arrows (which presumably are penalized more).

is there a variation to the dot tool that relies relatively less on automatic layout and more on manual layout? if dot had this, I could work around the bug by pushing up C3R1 … (but presumably, the order not being followed is the bug here.)

---

<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:** [March 30, 2021, 2:23am UTC](https://forum.graphviz.org/t/dot-more-layout-control/586/4 "2021-03-30T02:23:34Z")

</div>

My only suggestion for now is to run **dot -Tdot yourfile.gv \>yourfile.dot** This will give a text version of your file with positioning. You can edit this file - manually or programmatically - to reposition (swap) the nodes where you want them. (Edit the **pos** values) Don’t worry about the edges.  
Then run that thru neato **neato -n -Tpng yourfile.dot \>yourfile.png** The **-n** option will keep the (new) node positions but will redraw the edges. (See this [FAQ | Graphviz](https://www.graphviz.org/faq/#FaqDotWithNodeCoords))
