When using both subscript and superscripts on a node label, is it possible to alter the positioning so that they are directly above each other.
Example:
digraph G {
x11[label=<X<SUB>1</SUB><SUP>(1)</SUP>>];
x21[label=<X<SUB>2</SUB><SUP>(1)</SUP>>];
x11 -> x21
}
Which produces
Is it possible to have the (#)
directly above the #
rather than slightly to the right? thanks
I tried to add a custom css
script (re: HTML: can I place subscript text right under the superscript?)
to my dot
script with stylesheet = "styles.css";
(re: Using CSS classes in HTML labels on Graphviz), however, it it returns an error
Error: Unknown HTML element
<span>
on line 1
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:
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.
Per the Graphviz docs, their 'HTML-Like Labels' do not include the span element, and the font-styling tags do not allow the style attribute (or any other):
<SUB
<!-- No attributes -->
>
<SUP
<!-- No attributes -->
>
The two best options for precise text layout seem to be:
1) Use a label with an html-like table, which does allow for custom styling (and handles vertically placed text fine anyway).
x11[label=<
<TABLE border="0" cellborder="0" cellspacing="0">
<TR><TD rowspan="2" style="...">X</TD><TD style="...">(1)</TD></TR>
<TR> <TD style="...">1</TD></TR>
</TABLE>>];
2) If using the PostScript driver, override the node generation entirely and supply a ps file that draws exactly what you want.
Maybe we could introduce a more powerful HTML renderer (I just noticed litehtml, and sciter which is not open source) which probably has its own make system, potential security issues, its own font and color name management, shared strings, C++ compiler dependencies, memory leaks, and litehtml for instance is only 16K lines of code which these days barely moves the meter for us, just I always feel a little guilty when I see tweets about how building graphviz is harder than the linux kernel. Stephen North
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With