尝试使用 Tikz 在 TexMaker 中绘制自动机的图片

尝试使用 Tikz 在 TexMaker 中绘制自动机的图片

自动机的图片我在寻求帮助,如何在 TexMaker 中绘制自动机。我的问题是自动机的线条交叉,这让整个东西有点难以阅读。

梅威瑟:

\documentclass[a4paper,twoside,11pt]{article}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}

\begin{tikzpicture}[shorten >=1pt,node distance=2.5cm,on grid,auto]
   \node[state,initial] (0) {$q_0$};
   \node[state] (1) [right=of 0] {$q_1$};
   \node[state, accepting] (2) [right=of 1] {$q_2$};
   \node[state, accepting] (3) [right=of 2] {$q_3$};
   \node[state] (4) [right=of 3] {$q_4$};
   \path[->]
    (0) edge [bend left]    node {$a$} (2)
    (0) edge [loop below]   node {$b$} (0)
    (0) edge                node {$c$} (1)
    (1) edge                node {$a$} (2)
    (1) edge [bend left]    node {$b$} (4)
    (1) edge [loop below]   node {$c$} (1)
    (2) edge [bend right]   node {$a$} (0)
    (2) edge [loop below]   node {$b$} (2)
    (2) edge                node {$c$} (3)
    (3) edge [bend right]   node {$a$} (0)
    (3) edge                node {$b$} (4)
    (3) edge [loop below]   node {$c$} (3)
    (4) edge [loop below]   node {$a$, $b$, $c$} (4);
\end{tikzpicture}

\end{document}

答案1

弯曲选项可以采用一个值来控制弯曲程度。这样您就可以手动避免重叠。在这种情况下,您可以使边缘指向(0)低于状态,并且为了避免与环路发生冲突,它们可以弯曲成60度角bend left=60

\documentclass[a4paper,twoside,11pt]{article}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}

\begin{document}

\begin{tikzpicture}[shorten >=1pt,node distance=2.5cm,on grid,auto]
   \node[state,initial] (0) {$q_0$};
   \node[state] (1) [right=of 0] {$q_1$};
   \node[state, accepting] (2) [right=of 1] {$q_2$};
   \node[state, accepting] (3) [right=of 2] {$q_3$};
   \node[state] (4) [right=of 3] {$q_4$};
   \path[->]
    (0) edge [bend left]    node {$a$} (2)
    (0) edge [loop below]   node {$b$} (0)
    (0) edge                node {$c$} (1)
    (1) edge                node {$a$} (2)
    (1) edge [bend left]    node {$b$} (4)
    (1) edge [loop below]   node {$c$} (1)
    (2) edge [bend left=60]   node {$a$} (0)
    (2) edge [loop below]   node {$b$} (2)
    (2) edge                node {$c$} (3)
    (3) edge [bend left=60]   node {$a$} (0)
    (3) edge                node {$b$} (4)
    (3) edge [loop below]   node {$c$} (3)
    (4) edge [loop below]   node {$a$, $b$, $c$} (4);
\end{tikzpicture}

\end{document}

更好的

相关内容