Archive for September, 2010

How to: Embed dot graphs (graphviz) in LaTeX

Monday, September 13th, 2010

Dot graphs (from GraphViz) are known for their easiness in expressing complex graphs in a plain text format and generating those graphs file into static images. For example, look at the following dot graph:

digraph Example {
rankdir=LR;

node [shape="box",color="blue"]; q_0 q_1 q_2 q_3 q_4 q_6 q_7 q_8 q_9 q_10;
node [shape="circle",color="black"]; q_5;

q_0 -> q_1 [label="1"];
q_1 -> q_2 [label="1"];
q_2 -> q_3 [label="1"];
q_3 -> q_4 [label="1"];
q_4 -> q_5 [label="1"];
q_5 -> q_5 [label="0, 1"];

q_0 -> q_6 [label="0"];
q_1 -> q_7 [label="0"];
q_2 -> q_8 [label="0"];
q_3 -> q_9 [label="0"];
q_4 -> q_10 [label="0"];

q_6 -> q_7 [label="0, 1"];
q_7 -> q_8 [label="0, 1"];
q_8 -> q_9 [label="0, 1"];
q_9 -> q_10 [label="0, 1"];

q_10 -> q_0 [label="0, 1"];
}

A graph starts with “graph” or “digraph”, followed by its name. Properties of the graph are wrapped in a pair of accolades. In this example, the first property is “rankdir=LR“, which sets the orientation of the graph to left-to-right (instead of the default top-to-bottom). Line four and five define the appearance of each node used in the graph. At the end of this dot graph is a list of relations between the defined nodes. Below is the generated image of this graph.

automaton generated by GraphViz' dot graphs

automaton generated by GraphViz' dot graphs

(more…)