2

I want to obtain this result:

enter image description here

and so far I've written this code:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}
  \begin{tikzpicture}[%
  >=stealth,
  shorten >=1pt,
  node distance=2cm,
  on grid,
  auto,
  state/.append style={minimum size=2em},
  thick]
  \node[state] (q)               {$q$};
  \node[state] (m) [right of=q]  {};
  \node[state,double] (f) [right of=m] {$f$};

  \path[->] (q) +(-1,0) edge (q);
  \end{tikzpicture}
\end{document}

But I have no idea on how to do the coloured ellipses. I just need to group graphically a set of nodes and apply to them a label (in the example N(s) and N(t)), so I don't care about the specific representation.

1 Answers1

2

You need fit, shapes.geometric and backgrounds libraries.

enter image description here

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,fit,shapes.geometric,backgrounds}

\begin{document}
  \begin{tikzpicture}[%
  >=stealth,
  shorten >=1pt,
  node distance=2cm,
  on grid,
  auto,
  state/.append style={minimum size=2em},
  thick]
  \node[state, draw=red] (q)               {$q$};
  \node[state, draw=red!50!green] (m) [right of=q]  {};
  \node[state,double, draw=green] (f) [right of=m] {$f$};

\begin{scope}[on background layer]
\node[fit=(q) (m), ellipse, fill=red!30, draw=red, fill opacity=0.5, label=above:N(s)] (qm) {};
\node[fit=(m) (f), ellipse, fill=green!30, draw=green, fill opacity=0.5, label=above:N(t)] (mf) {};
\end{scope}

    \draw[->] ([xshift=-1cm]qm.west)--(q);
  \end{tikzpicture}
\end{document}
Ignasi
  • 136,588