How to prevent node position change when using xlabel in DOT?

I want to create a graph with GraphViz/DOT, render it to PNG and include it in a LaTeX beamer presentation.

I have included the PNG in the presentation in such a way that on the first page is a version without xlabel-attributes and on the second page at the exact same position should be a version with some external labels, so that it seems like the labels just appear.

However, GraphViz/DOT renders the graph with the xlabels in such a way that the original nodes are slightly moved away from the positions of the external labels, so the visual effect is that the whole graph moves at the page flip.

Is there a way to add external labels to an existing graph, so that the nodes don't change their positions, no matter if there are external labels or not, other than photoshopping the labels to the rendered PNG file?

My DOT code currently looks like this:

graph G {
graph [nodesep=1, ranksep=1, ratio=1]
a [xlabel="0"]
b [style=filled, fillcolor=red, xlabel="1"]
c [style=filled, color=green, xlabel="2"]
d [style=filled, color=green, xlabel="2"]
e [style=filled, color=green, xlabel="3"]
f [style=filled, color=green, xlabel="3"]
g [xlabel="1"]
h [xlabel="2"]
i [xlabel="3"]
j [xlabel="3"]
a -- b
a -- g
b -- c
b -- d
d -- e
d -- f
g -- h
h -- i
h -- j
}

Hi. Not sure as the drivers

Hi. Not sure as the drivers are designed to render the layout in the first quadrant at (0,0) 
but you might experiment with the nornalize attribute http://www.graphviz.org/doc/info/attrs.html#d:normalize

Stephen North

Recent comments