Nodes

\node[<options>] (name) {text label};
\usetikzlibrary{automata, positioning, arrows}
\tikzset{
	->, % makes the edges directed
	>=stealth, % makes the arrow heads bold
	node distance=3cm, % specifies the minimum distance between two nodes. Change if necessary.
	every state/.style={thick}, % sets the properties for each ’state’ node
	initial text=$Start$, % sets the text that appears on the start arrow
}
\begin{document}
	\begin{tikzpicture}
		\node[state] (q1) {$q_1$};
	\end{tikzpicture}
\end{document}

Options

  • state: Must be specified
  • initial: if it is a start state
  • accepting: if it is a acceptable state

Positioning

  • right/left/... of=<node>: \node[state, right of=q1] (q2) {$q_2$}
\usetikzlibrary{automata, positioning, arrows}
\tikzset{
	->, % makes the edges directed
	>=stealth, % makes the arrow heads bold
	node distance=3cm, % specifies the minimum distance between two nodes. Change if necessary.
	every state/.style={thick}, % sets the properties for each ’state’ node
	initial text=$Start$, % sets the text that appears on the start arrow
}
\begin{document}
	\begin{tikzpicture}
		\node[state] (q1) {$q_1$};
		\node[state, right of=q1] (q2) {$q_2$};
	\end{tikzpicture}
\end{document}
  • xshift=x, yshift=y: \node[state, right of=q1, yshift=1cm] (q2) {$q_2$}
\usetikzlibrary{automata, positioning, arrows}
\tikzset{
	->, % makes the edges directed
	>=stealth, % makes the arrow heads bold
	node distance=2.5cm, % specifies the minimum distance between two nodes. Change if necessary.
	every state/.style={thick}, % sets the properties for each ’state’ node
	initial text=$Start$, % sets the text that appears on the start arrow
}
\begin{document}
	\begin{tikzpicture}
		\node[state] (q1) {$q_1$};
		\node[state, right of=q1, yshift=1cm] (q2) {$q_2$};
	\end{tikzpicture}
\end{document}
  • at (x, y): \node[state] (q1) at (2, 3) {$q_1$}
\usetikzlibrary{automata, positioning, arrows}
\tikzset{
	->, % makes the edges directed
	>=stealth, % makes the arrow heads bold
	node distance=2.5cm, % specifies the minimum distance between two nodes. Change if necessary.
	every state/.style={thick}, % sets the properties for each ’state’ node
	initial text=$Start$, % sets the text that appears on the start arrow
}
\begin{document}
	\begin{tikzpicture}
		\node[state] (q2) {$q_2$};
		\node[state] (q1) at (2, 3) {$q_1$};
	\end{tikzpicture}
\end{document}

Edges

\draw (<source node>) edge[<edge options>] node{<edge label>} (<dest node>);
  • if the start and end is the same node, add loop above/below in <edge options>
  • if the edge is bending, add bend left/right in <edge options>
  • The edge labels can be positioned either above or below the edge, with the keywords above and below in the <edge options>

Example

DFA

where is defined as:

\usetikzlibrary{automata, positioning, arrows}
\tikzset{
	->, % makes the edges directed
	>=stealth, % makes the arrow heads bold
	node distance=2.5cm, % specifies the minimum distance between two nodes. Change if necessary.
	every state/.style={thick}, % sets the properties for each ’state’ node
	initial text=$Start$, % sets the text that appears on the start arrow
}
\begin{document}
	\begin{tikzpicture}
		\node[state, initial] (q1) {$q_1$};
		\node[state, accepting, right of=q1] (q2) {$q_2$};
		\node[state, right of=q2] (q3) {$q_3$};
		\draw (q1) edge[loop above] node{0} (q1)
			(q1) edge[above] node{1} (q2)
			(q2) edge[bend left, above] node{0} (q3)
			(q2) edge[loop above] node{1} (q2)
			(q3) edge[bend left, below] node{0, 1} (q2);
	\end{tikzpicture}
\end{document}