Drawing finite state automata with Tikz

Tikz offers a library for drawing finite state automata (FSA) for embedding in LaTeX. As I mostly use simple FSAs and for making the corresponding Tikz code more expressive, I created two new commands:

  • newState
    Each state has an internal name which may be referred to when drawing edges and a visible label. In contrast toother graph drawing tools such as GraphViz we need to provide positioning information for each node (above of/below of/right of/left of). Each state may bear additional properties such as whether it is an accepting state or  an initial state.
  • newTransition
    A transition connects a source state with a target state, given that some condition is fulfilled guard. An edge may be drawn as a straight line (default) or as an arc (bend left/bend right). For loops you need to use loop above/loop below etc.

Example FSA

Finite State Automaton drawn with Tikz

Finite State Automaton drawn with Tikz

The following example code defines an FSA which accepts words conforming to the regular expression b(an)+e:

GraphViz as an Alternative

Another candidate for drawing graphs is GraphViz, which I indeed tested first. GraphViz has some important drawbacks:

  • The subscript tag <SUB> and some others do not work for GraphViz before the version of October 14, 2011, and even then, only for PNG and SVG rendering.[1]
  • The font used for rendering by GraphViz is not synchronized with the font in the final LaTeX document which may be annoying.


  • [1] Martin Thoma’s site with another nice example
  • [2] texamples.net

Leave a Reply

Your email address will not be published. Required fields are marked *

Please type the characters of this captcha image in the input box

Please type the characters of this captcha image in the input box