Improve positioning of subscript and superscript on node labels

The native HTML-like node rendering of Graphviz is quite limited. The Graphviz docs say this clearly. I don’t believe there’s a way to coax it to do what you want. Even if there is a way to tweak e.g. a <table> definition to do it, the results are likely to look bad.

Therefore, I recommend you look at dot2tex. Its whole purpose is to allow the full power of LaTeX for rendering nodes. Setup isn’t trivial, but results are worth it.

Here’s a page showing examples of graphs containing LaTeX-set math in nodes.

You didn’t say what the output should be. But there are ways to convert LaTeX to many different forms. Easiest are Postscript and PDF. But images formats are also possible.

Addition

Okay I installed dot2tex, and here’s a result:

GraphViz graph with stacked subscripts under superscripts

Here’s the corresponding dot code:

digraph G {
  a_1 [texlbl="$X_{1}^{(1)}$"];
  a_2 [texlbl="$X_{1}^{(2)}$"];
  a_3 [texlbl="$X_{1}^{(3)}$"];
  a_1-> a_2 -> a_3 -> a_1;
}

I compiled with

$ dot2tex foo.gv -f tikz > foo.tex
$ pdflatex foo.tex

Since you’re already using LaTeX, you should be able to adjust this to meet your exact requirements without much trouble.

Leave a Comment

techhipbettruvabetnorabahisbahis forumu