Centering in DOT

Hi,

I hope this forum is suitable for posting my question.

How can I change my graph so that the + and / characters
are centered above its following characters?

Thank you.

stem


graph tree
{
graph [fontname="Arial"];
node [fontname="Arial",style=filled,color="#888888",fontsize=18];
edge [fontname="Arial"];
k1 [label="-"];
k2 [label="+"];
k3 [label="2"];
k4 [label="*"];
k5 [label="3"];
k6 [label="6"];
k7 [label="/"];
k8 [label="4"];
k9 [label="1"];
k1 -- k2 -- k3;
k2 -- k4 -- k5;
k4 -- k6;
k1 -- k7 -- k8;
k7 -- k9;
}

AttachmentSize
termbaum1.png15.44 KB

Dot is designed to compact

Dot is designed to compact the layout as much as possible, so asking for centering fights against it. You can tweak the graph with extra, invisible edges and nodes, but it is probably simpler to perform a slight adjustment to the dot layout: run

dot x.gv | gvpr -c -f tree.g | neato -n -Tpng > x.png

where x.gv is your input graph and tree.g is a file containing

BEGIN {
  double xs[node_t];
  double x;
  node_t n, rootn;

  node_t getRoot (graph_t g) {
    if (hasAttr(g,"root") && (n = isNode (g, aget(g,"root"))))
      return n;
    for (n = fstnode(g); n; n = nxtnode(n)) {
      if (n.indegree == 0) {
        return n;
      }
    }
    printf(2, "No root found\n");
    exit (1);
    return NULL;
  }
}
BEG_G {
  $tvroot = getRoot($);
  $tvtype = TV_postfwd;
}
N {
  if ($.outdegree > 0) {
    x = xs[$]/$.outdegree;
    $.pos = sprintf("%.5g,%s", x, yOf($.pos));
  }
  else
    x = (double)xOf($.pos);
  if ($tvedge) {
    n = $tvedge.tail;
    xs[n] += x;
  }
}

For a related discussion, see http://www.graphviz.org/content/fix-dot-overlap.

Thank you!

Thank you!

Recent comments