如何使用 TikZ、自动机库更改有限状态机中的初始状态文本?

如何使用 TikZ、自动机库更改有限状态机中的初始状态文本?

\node具有initial属性时,会出现一个文本“开始”。我们可以更改该文本吗?

答案1

您可以使用/tikz/initial text = <text>键值对

\documentclass[tikz, border = 5pt]{standalone}
\usetikzlibrary{automata}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[shorten >=1pt, node distance = 2cm, on grid, auto, initial text = \textcolor{red}{INITIAL}]
  \draw[help lines] (0,0) grid (3,2);
  \node[state, initial] (q_0) {$q_0$};
  \node[state] (q_1) [above right = of q_0] {$q_1$};
  \node[state] (q_2) [below right = of q_0] {$q_2$};
  \node[state, accepting](q_3) [below right = of q_1] {$q_3$};
  \path[->] (q_0) edge node {0} (q_1)
  edge node [swap] {1} (q_2)
  (q_1) edge node {1} (q_3)
  edge [loop above] node {0} ()
  (q_2) edge node [swap] {0} (q_3)
  edge [loop below] node {1} ();
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容