\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
\node[state,initial,accepting] (A) {$A$};
\node[state,accepting] (B) [above right=of A] {$B$};
\node[state,accepting] (C) [above right=of B] {$C$};
\node[state,accepting](D) [below right=of C] {$D$} [loop above];
\node[state](E) [below left=of A] {$\emptyset$} [loop above];
\path[->]
(A) edge node {a} (B)
edge node [swap] {b} (E)
(B) edge node {b} (C)
edge [loop above] node {a} ()
(C) edge node {a} (D) edge node [swap] {a}(B)
edge [loop above] node {b} ()
(E) edge [loop left] node {a,b}()
(D) edge node {a} (B) edge node {b} (E) () //this line is generating error?
;
////
\end{tikzpicture}
我不明白为什么会有错误?
答案1
edge node {b} (E) ()
此处解释为“将一个带有文本的节点放置b
在上一个活动坐标和 (E) 之间的边缘上,然后移动到坐标()
”。没有坐标()
,因此会出现错误。只需删除最后一对空括号即可。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,automata}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
\node[state,initial,accepting] (A) {$A$};
\node[state,accepting] (B) [above right=of A] {$B$};
\node[state,accepting] (C) [above right=of B] {$C$};
\node[state,accepting](D) [below right=of C] {$D$} [loop above];
\node[state](E) [below left=of A] {$\emptyset$} [loop above];
\path[->]
(A) edge node {a} (B)
edge node[swap] {b} (E)
(B) edge node[swap] {b} (C)
edge [loop above] node {a} ()
(C) edge node {a} (D)
edge node [swap] {a}(B)
edge [loop above] node {b} ()
(E) edge [loop left] node {a,b} ()
(D) edge node {a} (B)
edge node {b} (E);
\end{tikzpicture}
\end{document}