我尽力尝试绘制以下 FSA,但某些边缘仍然显示得不太好(因为它们不是弯曲的)并且状态 1 与其余部分不一致。
是否有可能:
也许可以让各州稍微小一点
将 1 与 2 对齐(使其位于正上方)
使边缘正确地适应 q1 -> q6 等等。例如,它应该是弯曲的而不是超过状态 3。
给边 1->4 和 2->3 留出一些空间,这样我就可以同时为它们两个写上文字。
梅威瑟:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,decorations.text,topaths,arrows.meta,decorations.pathmorphing,quotes}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
\node[state] (q_0) {$0$};
\node[state] (q_1) [above right=of q_0] {$1$};
\node[state] (q_2) [right=of q_0] {$2$};
\node[state] (q_11) [below=of q_2] {$11$};
\node[state] (q_3) [above right=of q_2] {$3$};
\node[state] (q_4) [below right=of q_3] {$4$};
\node[state] (q_5) [right=of q_3] {$5$};
\node[state] (q_6) [right=of q_5] {$6$};
\node[state] (q_7) [below right=of q_5] {$7$};
\node[state] (q_8) [right=of q_7] {$8$};
\node[state] (q_9) [right=of q_8] {$9$};
\node[state] (q_10) [right=of q_9] {$10$};
\path[->]
(q_0) edge node [swap] {b} (q_1)
edge node [swap] {b} (q_2)
edge node [swap] {b} (q_11)
(q_1) edge node [swap] {b} (q_4)
edge node [swap] {b} (q_5)
edge node [swap] {b} (q_6)
(q_2) edge node [swap] {b} (q_3)
edge node [swap] {b} (q_4)
(q_4) edge node [swap] {b} (q_7)
(q_6) edge node [swap] {b} (q_8)
(q_7) edge node [swap] {b} (q_8)
(q_8) edge node [swap] {b} (q_9)
(q_9) edge node [swap] {b} (q_10)
(q_11) edge node [swap] {b} (q_4);
\end{tikzpicture}
\end{document}
答案1
您可以使用in
和out
键使边缘变得“弯曲”。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,decorations.text,topaths,arrows.meta,decorations.pathmorphing,quotes}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
\node[state] (q_0) {$0$};
\node[state] (q_2) [right=of q_0] {$2$};
\node[state] (q_1) [above={sqrt(2)*1cm} of q_2] {$1$};
\node[state] (q_11) [below=of q_2] {$11$};
\node[state] (q_3) [above right=of q_2] {$3$};
\node[state] (q_4) [below right=of q_3] {$4$};
\node[state] (q_5) [right=of q_3] {$5$};
\node[state] (q_6) [right=of q_5] {$6$};
\node[state] (q_7) [below right=of q_5] {$7$};
\node[state] (q_8) [right=of q_7] {$8$};
\node[state] (q_9) [right=of q_8] {$9$};
\node[state] (q_10) [right=of q_9] {$10$};
\path[->]
(q_0) edge node [swap] {b} (q_1)
edge node [swap] {b} (q_2)
edge node [swap] {b} (q_11)
(q_1) edge node [pos=0.8] {b} (q_4)
edge[in=135,out=45] node [swap] {b} (q_5)
edge[in=135,out=90] node [swap] {b} (q_6)
(q_2) edge node [swap] {b} (q_3)
edge node [swap] {b} (q_4)
(q_4) edge node [swap] {b} (q_7)
(q_6) edge node [swap] {b} (q_8)
(q_7) edge node [swap] {b} (q_8)
(q_8) edge node [swap] {b} (q_9)
(q_9) edge node [swap] {b} (q_10)
(q_11) edge node [swap] {b} (q_4);
\end{tikzpicture}
\end{document}
就我个人而言,我会将 3 节点稍微向右移动。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,decorations.text,topaths,arrows.meta,decorations.pathmorphing,quotes}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
\node[state] (q_0) {$0$};
\node[state] (q_2) [right=of q_0] {$2$};
\node[state] (q_1) [above={sqrt(2)*1cm} of q_2] {$1$};
\node[state] (q_11) [below=of q_2] {$11$};
\node[state] (q_3) [right=of q_1] {$3$};
\node[state] (q_4) [below right=of q_3] {$4$};
\node[state] (q_5) [right=of q_3] {$5$};
\node[state] (q_6) [right=of q_5] {$6$};
\node[state] (q_7) [below right=of q_5] {$7$};
\node[state] (q_8) [right=of q_7] {$8$};
\node[state] (q_9) [right=of q_8] {$9$};
\node[state] (q_10) [right=of q_9] {$10$};
\path[->]
(q_0) edge node [swap] {b} (q_1)
edge node [swap] {b} (q_2)
edge node [swap] {b} (q_11)
(q_1) edge node [pos=0.8] {b} (q_4)
edge[in=135,out=45] node [swap] {b} (q_5)
edge[in=135,out=90] node [swap] {b} (q_6)
(q_2) edge node [swap] {b} (q_3)
edge node [swap] {b} (q_4)
(q_4) edge node [swap] {b} (q_7)
(q_6) edge node [swap] {b} (q_8)
(q_7) edge node [swap] {b} (q_8)
(q_8) edge node [swap] {b} (q_9)
(q_9) edge node [swap] {b} (q_10)
(q_11) edge node [swap] {b} (q_4);
\end{tikzpicture}
\end{document}