在自动机周围绘制箭头

在自动机周围绘制箭头

使用 Tikzpicture,我有以下自动机:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{positioning,arrows,automata}
\begin{center}
\begin{tikzpicture}[>=stealth',shorten >=1pt,node distance=2cm,on grid,initial/.style={}]
\node[state,initial]  (a0)                   {};
\node[state]          (a1)  [right =of a0]   {};
\node[state]          (a2)  [right =of a1]   {};
\node[state]          (a3)  [above =of a2]   {};
\node[state]          (a4)  [below =of a0]   {};
\node[state]          (a6)  [right =of a4]   {};
\node[state]          (a7)  [right =of a2]   {};   
\node[state]          (a8)  [right =of a7]   {};
\node[state]          (a9)  [right =of a8]   {}; 
\node[state]          (a5)  [above =of a9]   {};
\node[state]          (b0)  [right =of a6]   {}; 
\node[state]          (b1)  [right =of b0]   {};
\node[state]          (b2)  [right =of b1]   {}; 
\node[state]          (b3)  [right =of b2]   {};
\node[state]          (b4)  [right =of a9]   {};                                
\tikzset{every node/.style={fill=white}}
\tikzset{mystyle/.style={->,double=red}}  
\path (a4)     edge [mystyle]       node   {$0$} (a6)
      (a2)     edge [mystyle]       node   {$0$} (a7)
      (b0)     edge [mystyle]       node   {$0$} (b1);
\tikzset{mystyle/.style={->,double=blue}}  
\path (a3)     edge [mystyle]       node   {$1$} (a5)
      (a8)     edge [mystyle]       node   {$1$} (a9)
      (b2)     edge [mystyle]       node   {$1$} (b3);              
\tikzset{mystyle/.style={->,double=yellow}}  
\path (a0)     edge [mystyle]       node   {$\varepsilon$} (a1)
      (a1)     edge [mystyle]       node   {$\varepsilon$} (a2)
      (a1)     edge [mystyle]       node   {$\varepsilon$} (a3)
      (a1)     edge [mystyle]       node   {$\varepsilon$} (a4)
      (a6)     edge [mystyle]       node   {$\varepsilon$} (b0)
      (a7)     edge [mystyle]       node   {$\varepsilon$} (a8)
      (b1)     edge [mystyle]       node   {$\varepsilon$} (b2)
      (a9)     edge [mystyle]       node   {$\varepsilon$} (b4)
      (a5)     edge [mystyle]       node   {$\varepsilon$} (b4)
      (b3)     edge [mystyle]       node   {$\varepsilon$} (b4);
\end{tikzpicture}
\end{center}
\end{document}

结果

现在,我想添加一个黄色的 epsilon 箭头,从最左边的节点 (a0) 到最右边的节点 (b4)。但是,我完全不知道如何做到这一点,而不让箭头穿过自动机的其余部分。我可以在这里得到一些帮助吗?

答案1

您可以使用[bend left]评论中所建议的选项,并赋予它一个角度,例如[bend left=70],然后曲线将以该角度离开起点和终点节点,因此生成的路径是对称的。

(a0)   edge[mystyle, bend left=70] node {$\varepsilon$} (b4);

然而,在这种特殊情况下,由于图形不对称,这种生成路径的方式看起来有点丑陋(恕我直言):

有点丑

通过选项inout您可以为路径的结尾指定不同的角度,从而创建与图形其余部分更相配的不对称弧:

 (a0)   edge[mystyle, out=50,in=90] node {$\varepsilon$} (b4);

更好的

相关内容