如何在 TikZ 中的自动机中制作不同形状的节点?

如何在 TikZ 中的自动机中制作不同形状的节点?

这是我的代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,fit,calc,positioning,automata}

\begin{document}

\begin{tikzpicture}[shorten >=1pt,auto,node distance=7 cm, scale = 0.6, transform shape]

      \node[initial,state] (A)                      {$e, n, s$};
      \node[state]         (B) [right of=A]         {$w, (p+1)\%W, (p+1)\%N$};
      \node[state]         (C) [below of=A]     {$(q+1)\%W, n, x$};



\end{tikzpicture}

\end{document}

这是以下输出:

我怎样才能使它们全部大小相同?如何绘制椭圆以使其看起来不那么大?

答案1

可以定义状态elliptic,例如通过以下方式:

\tikzset{elliptic state/.style={draw,ellipse}}

需要ellipseshapes.geometric

代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shapes.geometric,arrows,fit,calc,positioning,automata,}

\begin{document}
\tikzset{elliptic state/.style={draw,ellipse}}
\begin{tikzpicture}[shorten >=1pt,auto,node distance=7 cm, scale = 0.6, transform shape]

      \node[initial,elliptic state] (A)                      {$e, n, s$};
      \node[elliptic state]         (B) [right of=A]         {$w, (p+1)\%W, (p+1)\%N$};
      \node[elliptic state]         (C) [below of=A]     {$(q+1)\%W, n, x$};

\end{tikzpicture}

\end{document}

结果:


为了使节点具有相同的大小,您可以指定形状的最小宽度和高度,但请注意,这最终取决于文本的宽度。

这个例子:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,shapes.geometric,arrows,fit,calc,positioning,automata,}

\begin{document}
\tikzset{elliptic state/.style={draw,ellipse,minimum width=6cm,minimum height=1.5cm}}
\begin{tikzpicture}[shorten >=1pt,auto,node distance=7 cm, scale = 0.6, transform shape]

  \node[initial,elliptic state] (A)                      {$e, n, s$};
  \node[elliptic state]         (B) [right of=A]         {$w, (p+1)\%W, (p+1)\%N$};
  \node[elliptic state]         (C) [below of=A]     {$(q+1)\%W, n, x$};

\end{tikzpicture}

\end{document}

结果:

相关内容