# How can I draw this Automata with Tikz?

I want something like the figure:

But what I got is:

this is my code:

\begin{center}
\begin{tikzpicture}[node distance=1.5cm]
% position the nodes a..d
\node (a) [] {$\textrm{I}$};
\node (b) [right of=a] {};
\node (c) [right of=b] {};
\node (d) [right of=c] {};
\node (e) [right of=d] {};
\node (f) [right of=e] {};
\node (g) [right of=f] {};
\node (h) [right of=g] {};
\node (i) [right of=h] {};
\node (j) [right of=i] {};
\node (k) [right of=j] {};
\node (l) [right of=k] {};

% draw the bullets/circles at the above defined positions
\filldraw (b) circle (1.5pt);

\filldraw (c) circle (1.5pt);

\filldraw (d) circle (1.5pt);

\filldraw (e) circle (1.5pt);

\filldraw (f) circle (1.5pt);
\draw (f) circle (5pt);

\filldraw (g) circle (1.5pt);

\filldraw (h) circle (1.5pt);

\filldraw (i) circle (1.5pt);

\filldraw (j) circle (1.5pt);

\filldraw (k) circle (1.5pt);

\filldraw (l) circle (1.5pt);
\draw (l) circle (5pt);

% draw arrows/connections, use 'shorten' to finetune space
\path[draw, ->, shorten >=3pt, shorten <=-2pt] (a) -- (b) ;
\draw[->, shorten >=1pt, shorten <=3pt] (b) -- (c)
node [above=0pt, pos=0.5, font=\footnotesize]{$\varepsilon$};
\draw[->, shorten >=1pt, shorten <=3pt] (c) -- (d)
node [above=0pt, pos=0.5, font=\footnotesize]{$1$};
\draw[->, shorten >=1pt, shorten <=3pt] (d) -- (e)
node [above=0pt, pos=0.5, font=\footnotesize]{$\varepsilon$};
\draw[->, shorten >=1pt, shorten <=3pt] (e) -- (f)
node [above=0pt, pos=0.5, font=\footnotesize]{$0$};

\path[->, shorten >=3pt, shorten <=1pt, bend left]
(b) edge node [above=0., pos=0.5, font=\footnotesize]{$\varepsilon$} (g) ;
\draw[->, shorten >=1pt, shorten <=3pt] (g) -- (h)
node [above=0pt, pos=0.5, font=\footnotesize]{$0$};
\draw[->, shorten >=1pt, shorten <=3pt] (h) -- (i)
node [above=0pt, pos=0.5, font=\footnotesize]{$\varepsilon$};
\draw[->, shorten >=1pt, shorten <=3pt] (i) -- (j)
node [above=0pt, pos=0.5, font=\footnotesize]{$0$};
\draw[->, shorten >=1pt, shorten <=3pt] (j) -- (k)
node [above=0pt, pos=0.5, font=\footnotesize]{$\varepsilon$};
\draw[->, shorten >=1pt, shorten <=3pt] (k) -- (l)
node [above=0pt, pos=0.5, font=\footnotesize]{$1$};
\end{tikzpicture}
\end{center}


Does anyone know how to make the graph look like the first figure (Photograph)?

You can use below right, above right etc. in order to position nodes in those directions, relative to the current node. It requires the positioning library to access the extra options.

Also, you could add a few custom styles to avoid repetition.

The example

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{center}
\begin{tikzpicture}[
node distance=1.5cm,
every node/.style={draw, fill, circle, inner sep=1.5pt},
endnode/.style={fill=none, inner sep=5pt},
every edge/.style={draw, ->, shorten >=5pt, shorten <=5pt},
itslabel/.style={draw=none, fill=none, above=0pt, pos=0.5},
]
% position the nodes a..d
\node (a) [draw=none,fill=none, font=\large] {I};
\node (b) [right=of a] {};
\node (c) [above right=of b] {};
\node (d) [right=of c] {};
\node (e) [right=of d] {};
\node (f) [right=of e] {};
\node (fend) [endnode] at (f) {};
\node (g) [below right=of b] {};
\node (h) [right=of g] {};
\node (i) [right=of h] {};
\node (j) [right=of i] {};
\node (k) [right=of j] {};
\node (l) [right=of k] {};
\node (lend) [endnode] at (l) {};

\path (a.center) edge (b)
(b) edge node [itslabel, pos=0.38, above=5pt] {$$\varepsilon$$} (c)
(c) edge node [itslabel] {$$1$$} (d)
(d) edge node [itslabel] {$$\varepsilon$$} (e)
(e) edge [shorten >=1em] node [itslabel] {0} (f)
(b) edge node [itslabel, pos=0.32, below=5pt] {$$\varepsilon$$} (g)
(g) edge node [itslabel] {$$0$$} (h)
(h) edge node [itslabel] {$$\varepsilon$$} (i)
(i) edge node [itslabel] {$$0$$} (j)
(j) edge node [itslabel] {$$\varepsilon$$} (k)
(k) edge [shorten >=1em] node [itslabel] {$$1$$} (l);
\end{tikzpicture}
\end{center}

\end{document}


• Sorry, I think I wasn't very clear in the question. The size of the vertices and edges that I got in the output were meeting my needs. I want only the arrangement of the vertices to change in relation to the output I got. Could you please change the code you sent so that the graph goes back to its default size?
– B612
Apr 23 at 20:19
• @B612 I think this should do. If you want to adjust the size of black nodes, change the value of inner sep in the line: every node/.style={draw, fill, circle, inner sep=1.5pt}. Circles with dotes, which I called endnodes are defined in the following line. Apr 23 at 20:29