我想要获得这个结果:
到目前为止我已经写了这段代码:
\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}
但我不知道如何制作彩色椭圆。我只需要以图形方式对一组节点进行分组并为它们应用标签(在示例中为 N(s) 和 N(t)),因此我并不关心具体的表示。
答案1
您需要fit
,shapes.geometric
和backgrounds
图书馆。
\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}