Edit: thanks to Zarko's answer (+1), I realized that I had not tried the obvious ellipse
style (or shape=ellipse
) correctly: I had only tried \node[ellipse, state, ...
which doesn't give the expected result because, most probably, state
implies the circle
shape, thus overriding the ellipse
style if used in this order. However, with \usetikzlibrary{shapes.geometric}
, \node[state, ellipse, ...
allows one to draw a state node with an elliptical shape. Therefore, the easiest way would be:
\documentclass[tikz,12pt,border=1mm]{standalone}
\usetikzlibrary{automata, shapes.geometric}
\begin{document}
\begin{tikzpicture}[
->, >=stealth,
node distance=3cm,
every state/.style={thick, fill=gray!10},
initial text={$I$},
]
\node[state, initial, accepting] (Q1) at (0,0) {$\{q_1\}$};
\node[state, ellipse, accepting] (Q2) at (3,0) {$\{q_1, q_2, q_3\}$};
\draw (Q1) edge [above] node {$a$} (Q2);
\draw (Q2.10) .. controls +(40:3mm) and +(90:2mm) .. ([xshift=3.3mm] Q2.east)
node[right] {$a$} .. controls +(-90:2mm) and +(-40:3mm) .. (Q2.-10);
\end{tikzpicture}
\end{document}

For the loop, I obtained the best results by choosing Bézier control points manually, as in the preceding code.
The rest is my first idea that uses \scalebox
and the xscale
transformation in order to draw the elliptical state. It's a little bit more complicated, but gives good control over the size and eccentricity of the ellipse.
In order to keep the font shape inside your (Q2)
node unchanged, I first horizontally scale the node contents by the inverse of the factor that I use to scale the whole circle
-shaped node (0.5 × 2 = 1 → the text shape is unchanged).
\documentclass[tikz,12pt,border=1mm]{standalone}
\usepackage{graphicx} % for \scalebox
\usetikzlibrary{automata}
\begin{document}
\begin{tikzpicture}[
->, >=stealth,
node distance=3cm,
every state/.style={thick, fill=gray!10},
initial text={$I$},
]
\node[state, initial, accepting] (Q1) at (0,0) {$\{q_1\}$};
\node[xscale=2, transform shape, state, accepting] (Q2) at (3,0) {%
\scalebox{0.5}[1]{$\{q_1, q_2, q_3\}$}};
\draw (Q1) edge [above] node {$a$} (Q2);
\draw (Q2.20) .. controls +(45:4mm) and +(90:3mm) .. ([xshift=5mm] Q2.east)
node[right] {$a$} .. controls +(-90:3mm) and +(-45:4mm) .. (Q2.-20);
\end{tikzpicture}
\end{document}

Smaller loop:
\draw (Q2.20) .. controls +(40:3mm) and +(90:2mm) .. ([xshift=3.5mm] Q2.east)
node[right] {$a$} .. controls +(-90:2mm) and +(-40:3mm) .. (Q2.-20);

Here is a simpler way for the loop, but it's a bit further from your drawing (the in
and out
angles are notably different; if you change them, the arrow will not start from and end at the same points on the node border):
\draw (Q1) edge [above] node {$a$} (Q2)
(Q2) edge [loop right, looseness=4] node {$a$} (Q2);
