如何在 tikz 中绘制双圆节点?

如何在 tikz 中绘制双圆节点?

考虑以下代码:

\begin{document}



\begin{figure}
\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=5 cm, scale = 1, transform shape]


\node[initial,state] (A)                                    {$s_0$};
\node[state]         (B) [right of=A]                       {$s_2$};
\node[state]         (C) [above of=B]                       {$s_1$};
\node[state]         (D) [below of=B]                       {$s_3$};

\path[->] (A) edge [left]       node [align=center]  {$ c = c + 1 $} (C)
      (A) edge [above]      node [align=center]  {$ c = c + 5 $} (B)
      (A) edge [left]       node [align=center]  {$ c = c - 1 $} (D)
      (B) edge [right]      node [align=center]  {$ c = c - 1 $} (D)
      (C) edge [loop above] node [align=center]  {$ c = c + 1 $} (C)
      (D) edge [loop below] node [align=center]  {$ c = c - 2 $} (D);

\end{tikzpicture}
\caption{An example of SST}
\end{figure}

\end{document}

我得到以下自动机: 在此处输入图片描述

我如何将 S2 和 S4 画为最终状态(双圆)?

答案1

这可以通过选项来实现accepting(参见参考25 自动机绘图库在 2012 年 4 月 25 日的 pgfmanual 版本中)。

代码(我假设s_1s_3作为最终状态):

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{automata,arrows}

\begin{document}
\begin{figure}
\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=5 cm, scale = 1, transform shape]


\node[initial,state] (A)                                    {$s_0$};
\node[state]         (B) [right of=A]                       {$s_2$};
\node[state,accepting]         (C) [above of=B]                       {$s_1$};
\node[state,accepting]         (D) [below of=B]                       {$s_3$};

\path[->] (A) edge [left]       node [align=center]  {$ c = c + 1 $} (C)
      (A) edge [above]      node [align=center]  {$ c = c + 5 $} (B)
      (A) edge [left]       node [align=center]  {$ c = c - 1 $} (D)
      (B) edge [right]      node [align=center]  {$ c = c - 1 $} (D)
      (C) edge [loop above] node [align=center]  {$ c = c + 1 $} (C)
      (D) edge [loop below] node [align=center]  {$ c = c - 2 $} (D);

\end{tikzpicture}
\caption{An example of SST}
\end{figure}

\end{document}

在此处输入图片描述

相关内容