# Adjusting Node Placement

**URL:** <https://forum.graphviz.org/t/adjusting-node-placement/298>\
**Category:** Help\
**Created:** [August 10, 2020, 10:31pm UTC](https://forum.graphviz.org/t/adjusting-node-placement/298 "2020-08-10T22:31:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![milliliter](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@milliliter](https://forum.graphviz.org/u/milliliter)\
**Post date:** [August 10, 2020, 10:31pm UTC](https://forum.graphviz.org/t/adjusting-node-placement/298/1 "2020-08-10T22:31:12Z")

</div>

The last step in all of my graphs (rendered with dot) is fine-tuning their appearance. I have tried a number of strategies, but maybe someone has something I haven’t tried.  
Here’s what I’ve done so far:

1. adjusting the weight of edges  
This is often an easy way to move two connected nodes closer together, but it also tries to make the edge straight, so sometimes it moves those nodes closer to the middle of the graph. And it usually has unintended consequences. In this graph, I’m repositioning mantrahS, mementoL, and reminiscentia, but those aren’t the only nodes that move. (Making the digraph strict lets me add edge weights to the bottom of the code, which makes it easier to change them later.)

[dot]  
strict digraph men {  
node [shape=none]  
edge [arrowsize=.5]  
nodesep=.05  
men -\> {gamundiz mensL meminisse reminisci monere mnemon mantrahS} [sametail=1]  
gamundiz -\> gemynd -\> ymund -\> mind  
mensL -\> mentalis -\> mentalOF -\> mentalME -\> mental  
meminisse -\> mementoL -\> memento  
reminisci -\> reminiscentia -\> reminiscence  
monere -\> praemonere -\> praemonitio -\> premonition  
mnemon -\> mnemonikosG -\> mnemonicusL -\> mnemonic  
mantrahS -\> mantra  
{rank=sink mind mental memento reminiscence premonition mnemonic mantra}  
}  
[/dot]  
[dot]  
strict digraph men {  
node [shape=none]  
edge [arrowsize=.5]  
nodesep=.05  
men -\> {gamundiz mensL meminisse reminisci monere mnemon mantrahS} [sametail=1]  
gamundiz -\> gemynd -\> ymund -\> mind  
mensL -\> mentalis -\> mentalOF -\> mentalME -\> mental  
meminisse -\> mementoL -\> memento  
reminisci -\> reminiscentia -\> reminiscence  
monere -\> praemonere -\> praemonitio -\> premonition  
mnemon -\> mnemonikosG -\> mnemonicusL -\> mnemonic  
mantrahS -\> mantra  
{rank=sink mind mental memento reminiscence premonition mnemonic mantra}  
men -\> mantrahS [weight=2]  
}  
[/dot]  
[dot]  
strict digraph men {  
node [shape=none]  
edge [arrowsize=.5]  
nodesep=.05  
men -\> {gamundiz mensL meminisse reminisci monere mnemon mantrahS} [sametail=1]  
gamundiz -\> gemynd -\> ymund -\> mind  
mensL -\> mentalis -\> mentalOF -\> mentalME -\> mental  
meminisse -\> mementoL -\> memento  
reminisci -\> reminiscentia -\> reminiscence  
monere -\> praemonere -\> praemonitio -\> premonition  
mnemon -\> mnemonikosG -\> mnemonicusL -\> mnemonic  
mantrahS -\> mantra  
{rank=sink mind mental memento reminiscence premonition mnemonic mantra}  
men -\> mantrahS [weight=2]  
meminisse -\> mementoL [weight=2]  
}  
[/dot]  
[dot]  
strict digraph men {  
node [shape=none]  
edge [arrowsize=.5]  
nodesep=.05  
men -\> {gamundiz mensL meminisse reminisci monere mnemon mantrahS} [sametail=1]  
gamundiz -\> gemynd -\> ymund -\> mind  
mensL -\> mentalis -\> mentalOF -\> mentalME -\> mental  
meminisse -\> mementoL -\> memento  
reminisci -\> reminiscentia -\> reminiscence  
monere -\> praemonere -\> praemonitio -\> premonition  
mnemon -\> mnemonikosG -\> mnemonicusL -\> mnemonic  
mantrahS -\> mantra  
{rank=sink mind mental memento reminiscence premonition mnemonic mantra}  
men -\> mantrahS [weight=2]  
meminisse -\> mementoL [weight=2]  
reminisci -\> reminiscentia [weight=2]  
}  
[/dot]

1. rank=same  
I always use this (or rank=sink, which has the same effect in all of my graphs) to align the bottom row, and sometimes I add more subgraphs at the end to fine-tune. Sometimes I’d rather have the nodes staggered to take up less horizontal space, though, and I don’t think that’s a thing GraphViz does. I’ve tried using an invisible parallel graph to enforce an order on all the ranks, but the minimum ranksep seems to be .1, which is too big if I want to define a lot of ranks and make each edge of my visible graph span at least two ranks.
2. style=invis  
There may be more I could do with invisible edges and nodes, but I don’t want them to make the finished graph bigger.
3. clusters  
Ideally, I’d divide the graph into a number of ordered horizontal strata and tell the graph which stratum to place each node in. Or divide a left-to-right graph into vertical strata. Clusters definitely don’t do that. At all.

Going back to rank=same, there’s one more thing on my wishlist, though I don’t need it. It lines up the centers of all the nodes in a subgraph, which is great for uniform nodes. But on this graph, I’d rather line up the bottoms of all the nodes:

 ![gen](https://global.discourse-cdn.com/graphviz/original/1X/b5c93696c01b451cf6dc5297fd3e480d50c1ef13.png)  
(FYI, not a problem, but the integrated dot renderer didn’t like my HTML-style labels.)

---

<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:** [August 11, 2020, 2:25pm UTC](https://forum.graphviz.org/t/adjusting-node-placement/298/2 "2020-08-11T14:25:52Z")

</div>

> [@milliliter](#):
>
> the integrated dot renderer didn’t like my HTML-style labels

Did you put the DOT source within backticks or within code tags? See [Render Graphviz graphs directly in your posts](https://forum.graphviz.org/t/render-graphviz-graphs-directly-in-your-posts/125#preventing-forum-formatting-to-interfere-with-dot-source-code)

---

<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:** [August 11, 2020, 5:34pm UTC](https://forum.graphviz.org/t/adjusting-node-placement/298/3 "2020-08-11T17:34:58Z")

</div>

Yep, repositioning nodes, edges, and clusters is often difficult. Each of the three has its own challenges. (I think cluster wrangling is the hardest).

1. for the **men** graph, did you consider placing each of the desired ranks in a subgraph with **rank=same**? Like:  
`{rank=same gemynd mentalis mementoL remeniscentia praemonere ...}`
2. yes, **rank=same** often does what I want, but sometimes it’s like working with a two-year-old
3. **style=invis** often very helpful. An indirect solution, but often very helpful.
4. clusters are the hardest. You can try padding them with invisible nodes & edges, but only if you have strong drink available.
5. wishlist - you can line up (justify) your mondo node at the top by adding many newlines to the end of your smaller nodes. But bottom justification is a real challenge.
6. Many of these types of problems can be addressed by pre-processing the **.gv** program or post-processing the ( **-Tdot** ) output using the built-in **gvpr** language or your language of choice. Some tweaks can be trivial, but there are few general-purpose tweak programs yet (see **Tool manual pages** on the **Documentation** web page)
