# Question about nodesep ranksep and minlen attributes in dot layout

**URL:** https://forum.graphviz.org/t/question-about-nodesep-ranksep-and-minlen-attributes-in-dot-layout/1365
**Category:** Help
**Created:** [November 13, 2022, 11:58pm UTC](https://forum.graphviz.org/t/question-about-nodesep-ranksep-and-minlen-attributes-in-dot-layout/1365 "2022-11-13T23:58:51Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![kasra](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/kasra/32/563_2.png) [@kasra](https://forum.graphviz.org/u/kasra)
#### Post date: [November 13, 2022, 11:58pm UTC](https://forum.graphviz.org/t/question-about-nodesep-ranksep-and-minlen-attributes-in-dot-layout/1365/1 "2022-11-13T23:58:51Z")

</div>

Hi,

let’s say we have this graph

```auto
digraph {  
    graph[rankdir=TB nodesep=0.02 ranksep=0.02]
    edge[arrowsize=0 style=invis minlen=1 len=0]
    node[shape=rect]
    a b c
    a->b[constraint=false]
    a -> c 
}

```

The documentation says for  
[ranksep](https://graphviz.org/docs/attrs/ranksep/)  
Specifies separation between ranks (type: double | doubleList, default: 0.5 (dot) , 1.0 (twopi) , **minimum: 0.02** )  
In dot, sets the desired rank separation, in inches.  
**This is the minimum vertical distance between the bottom of the nodes in one rank and the tops of nodes in the next**

[minlen](https://graphviz.org/docs/attrs/minlen/)  
Minimum edge length ( **rank difference between head and tai** l) type: int, default: 1, minimum: 0

Based on my comprehension, **my expectation is to have a distance of 0.02inch between a and c.**

But I have this :  
 ![test](https://global.discourse-cdn.com/graphviz/original/1X/2b97c070189c2085839d8b76d94801d537f432bd.png)

Could you explain to me why I have this gap?  
Is the edge responsible for something?

Thanks,

---

<div class="post-metadata">

### Author: ![smattr](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/smattr/32/85_2.png) [@smattr](https://forum.graphviz.org/u/smattr)
#### Post date: [November 14, 2022, 3:57pm UTC](https://forum.graphviz.org/t/question-about-nodesep-ranksep-and-minlen-attributes-in-dot-layout/1365/2 "2022-11-14T15:57:39Z")

</div>

My monthly PSA: the forum supports code blocks with Graphviz syntax highlighting:

````auto
```dot
digraph {
  like -> so[with="a label"];
}
```

````

which produces:

```nohighlight
digraph {
  like -> so[with="a label"];
}

```

---

<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: [November 14, 2022, 5:44pm UTC](https://forum.graphviz.org/t/question-about-nodesep-ranksep-and-minlen-attributes-in-dot-layout/1365/3 "2022-11-14T17:44:06Z")

</div>

Good question. It seems to be strictly related to rank. So **ranksep** should do the trick.  
Removing all references to edges does not change things.

```auto
digraph {
//rankdir=LR
graph[nodesep=0 ranksep=.02]
node[shape=circle]
{rank=source a b}
{rank=sink c}
}

```

Gives:  
 ![snuggedup0](https://global.discourse-cdn.com/graphviz/original/1X/50b5b357f80f5997b81b33b5b951ed9a18704734.png)

---

<div class="post-metadata">

### Author: ![kasra](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/kasra/32/563_2.png) [@kasra](https://forum.graphviz.org/u/kasra)
#### Post date: [November 14, 2022, 8:05pm UTC](https://forum.graphviz.org/t/question-about-nodesep-ranksep-and-minlen-attributes-in-dot-layout/1365/4 "2022-11-14T20:05:16Z")

</div>

I explored the documentation but so far I didn’t find any solution.  
I am sure there is a way otherwise It’s really surprising.  
Do you think that it’s a bug ? or the documentation is not correct?  
I think I am missing something 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: [November 14, 2022, 8:50pm UTC](https://forum.graphviz.org/t/question-about-nodesep-ranksep-and-minlen-attributes-in-dot-layout/1365/5 "2022-11-14T20:50:38Z")

</div>

My guess is that it is a bug/feature - working as originally designed but incorrectly documented. The clearest documentation I found is here [http://www.graphviz.org/pdf/dotguide.pdf](http://www.graphviz.org/pdf/dotguide.pdf). Addressing **ranksep** , it says:

> The second deals with rank separation, which is the minimum vertical space between the bottoms of nodes in one rank and the tops of nodes in the next.

Generally, I believe the developers expected users to use **record** and **html** nodes to create nodes that abutted each other

---

<div class="post-metadata">

### Author: ![scnorth](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/scnorth/32/89_2.png) [@scnorth](https://forum.graphviz.org/u/scnorth)
#### Post date: [November 15, 2022, 5:03pm UTC](https://forum.graphviz.org/t/question-about-nodesep-ranksep-and-minlen-attributes-in-dot-layout/1365/6 "2022-11-15T17:03:39Z")

</div>

This appears to be a bug. The relevant code is in `set_ycoords`

```
while (--r >= GD_minrank(g)) {
d0 = rank[r + 1].pht2 + rank[r].pht1 + GD_ranksep(g);	/* prim node sep */
d1 = rank[r + 1].ht2 + rank[r].ht1 + CL_OFFSET;	/* cluster sep */
delta = MAX(d0, d1);
if (rank[r].n > 0)	/* this may reflect some problem */
	(ND_coord(rank[r].v[0])).y = (ND_coord(rank[r + 1].v[0])).y + delta;

```

Notice that because of the definition of delta from d1, the offset between ranks can never be less than `CL_OFFSET`. I don’t know why we believed this. The subsequent comment about needing a guard to skip potentially empty ranks is a little unsettling but doesn’t seem to be a problem, it’s just conservative coding, I would like to think. I don’t see why one multiple of CL\_OFFSET is necessarily even enough. I don’t see any recursion in set\_ycoords so not sure how nesting of clusters is accounted for. The whole thing seems a little foolish; why not just solve a second linear program for y coords. Our code is too brittle.

---

<div class="post-metadata">

### Author: ![kasra](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/kasra/32/563_2.png) [@kasra](https://forum.graphviz.org/u/kasra)
#### Post date: [November 16, 2022, 2:06pm UTC](https://forum.graphviz.org/t/question-about-nodesep-ranksep-and-minlen-attributes-in-dot-layout/1365/7 "2022-11-16T14:06:13Z")

</div>

Thanks for your investigation.

Should I open an issue in the repo?

---

<div class="post-metadata">

### Author: ![mark](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/mark/32/84_2.png) [@mark](https://forum.graphviz.org/u/mark)
#### Post date: [November 17, 2022, 6:57am UTC](https://forum.graphviz.org/t/question-about-nodesep-ranksep-and-minlen-attributes-in-dot-layout/1365/8 "2022-11-17T06:57:41Z")

</div>

Good idea
