I want to draw two automata in a tikz
picture. The second automaton should be below the first, and both should be centered horizontally.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{automata, positioning}
\begin{document}
\begin{tikzpicture}[node distance=15mm, auto]
% first automaton
\node[state,initial] (sA) {$A$};
\node[state,accepting] (sB) [right of=sA] {$B$};
\path[->] (sA) edge[loop below] node {$0$} ()
(sA) edge[bend left] node {$1$} (sB)
(sB) edge[bend left] node {$0$} (sA);
% second automaton
\node[state,initial] (s0) [below=15mm of sA] {$s_0$};
\node[state] (s1) [right of=s0] {$s_1$};
\node[state,accepting] (s2) [right of=s1] {$s_2$};
\path[->] (s0) edge node {$a$} (s1)
(s1) edge node {$b$} (s2);
\end{tikzpicture}
\end{document}
How is the best way of getting the automata centered?
EDIT: The standalone
class is used here only for illustration purposes. I really intend to use the beamer
class.
Best Answer
An easy fix that will work in most classes (other than
standalone
) is to dedicate atikzpicture
to each automaton (if you can afford it) and use the\centering
declaration.Make sure to leave a blank line between the two
tikzpicture
environments. You can also add some vertical space between the two.EDIT: as Gonzalo Medina points out, there is no point in using a float environment, since the class used is
beamer
. In that case, combiningminipage
and\centering
will do the trick. Acenter
environment can also be used, but takes more vertical space than the latter.