[Tex/LaTex] How to use overlays in beamer when producing graphs with dot


I usually describe graphs with graphiz and I enjoy dot2tex which produces the corresponding TikZ code.

To explain an algorithm in a presentation, I need to uncover the nodes and edges of a graph step by step (without changing the layout, of course). I can find some documentation on how to do that when one is writing directly tikz code, for instance Beamer vs. TikZ: uncover nodes step-by-step , but in my case the code is generated automatically from the dot specification. Is it possible to include overlay specification in the dot file?

Best Answer

I think that in the dot file you could just include overlay specification for labels. Here is an example of dot file (I call it mygraph.dot):

digraph G {
  1 [texlbl="{\visible<1->{1}}"]; 
  2 [texlbl="{\visible<2->{2}}"];
  3 [texlbl="{\visible<3->{3}}"]; 
  1->2 [label="1/2"];
  2->3 [label="1/2"];
  3->1 [label="1/2"];

Now with the terminal you can create the correspondent TikZ code:

 dot2tex -ftikz mygraph.dot > mygraph.tex

As you know, mygraph.tex is a complete tex document, thus you just have to copy the code of the picture in your presentation. Notice that this applies just for nodes labels, not edge label.

The best way to proceed is:

  • export the dot file in a tex document;
  • edit the picture inserting \pause.

Coming back after one year more or less...

Actually, using overlay specification with GraphViz is perfectly doable by means of the famous Daniel's style visible on from Mindmap tikzpicture in beamer (reveal step by step). Since it is a style, it can be included in the dot file by means of the key style and it does the job for vertices and edges; for the labels, it's possible to exploit the construct {\visible<overlay specification>{label}} or, again the visible on style inside the key lblstyle.

An example:


  visible on/.style={alt=#1{}{invisible}},
  alt/.code args={<#1>#2#3}{%
    \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
  state st/.style={draw,circle,top color=orange!2,bottom color=red!50!orange!50}


\begin{frame}[fragile]{My graph}
\begin{dot2tex}[styleonly,codeonly,circo,options=-s -tmath]
digraph G {
  1 [style="state st,visible on=<2->"]; 
  2 [style="state st,visible on=<3->"]; 
  3 [style="state st,visible on=<4->"];  
  1->2 [label="1/2",style="visible on=<3->",lblstyle="visible on=<3->"];
  2->3 [label="1/2",style="visible on=<4->",lblstyle="visible on=<4->"];
  3->1 [label="1/2",style="visible on=<5->",lblstyle="visible on=<5->"];


The result:

enter image description here

Assuming the file be called anim-graph.tex, it must be compiled as:

pdflatex -shell-escape anim-graph.tex

since the package dot2texi requires to run dot2tex.

Related Question