我正在使用 tikzpictures 包制作图表。不幸的是,我的图表有点拥挤,迫使我使用额外的状态来保持其整洁有序。有没有办法延长某些箭头的长度。
我的代码如下。我想确保状态 5 和 8 可以合并为一个状态,而不会干扰其他状态。
\begin{tikzpicture}[->,shorten >=1pt,auto,node distance=3cm,
thick,main node/.style={circle,draw,font=\sffamily\large\bfseries}]
\node[main node] (S) {$q_s$};
\node[main node] (1)[above right of=S] {$q_1$};
\node[main node] (2)[above right of=1] {$q_2$};
\node[main node] (3)[above right of=2]{$q_3$};
\node[main node] (4)[below right of=3] {$q_4$};
\node[main node] (5)[below right of=1] {$q_5$};
\node[main node] (6)[above right of=5] {$q_6$};
\node[main node] (7)[below right of=5] {$q_7$};
\node[main node] (8)[below right of=6] {$q_8$};
\node[main node] (9)[below right of=S] {$q_9$};
\node[main node] (10)[below right of=9]{$q_a$};
\node[main node] (11)[below right of=10]{$q_b$};
\node[main node] (12)[above right of=11]{$q_c$};
\node[main node] (13)[above right of=8] {$q_d$};
\node[main node] (14)[below right of=8] {$q_e$};
\node[main node] (15)[right of=13] {$q_f$};
\node[main node] (16)[right of=14]{$q_g$};
%\node[main node] (16)[above right of=15] {$q_g$};
%\node[main node] (17)[below right of=15] {$q_h$};
\path[every node/.style={font=\sffamily\small}]
(S) edge node {1} (1)
edge node[below left] {0} (9)
(1) edge node {0} (5)
edge node {1} (2)
(2) edge node {1} (3)
edge node[left] {0} (6)
(3) edge[loop above] node {1} (3)
edge[bend right] node[left] {0} (6)
(4) edge[loop right] node {0} (4)
edge node[right] {1} (3)
(5) edge node {} (8)
(6) edge [bend right] node[right] {1} (3)
edge node[right] {0} (4)
(7) edge[loop above] node {0} (7)
edge[bend right] node[left] {1} (11)
(8) edge node[left] {1} (14)
edge node [left] {0} (13)
(9) edge node [below left] {0} (10)
edge node[below right] {1} (5)
(10) edge node[below left] {1} (11)
edge node {0} (7)
(11) edge node[below right] {1} (12)
edge[bend right] node[right] {0} (7)
(12) edge [loop right] node {1} (12)
edge node[right] {0} (7)
(13) edge [loop above] node {0} (13)
edge node {1} (15)
(14) edge [loop below] node {1} (14)
edge node[below] {0} (16)
(15) edge node {} (14)
edge[bend right] node {0} (16)
(16) edge node {} (13)
edge[bend right] node {1} (15)
%(16) edge[loop above] node {0} (16)
%(17) edge[loop below] node {1} (17)
\end{tikzpicture}
答案1
欢迎!这将节点 5 和 8 合并为一个。更重要的是,它使用positioning
库进行更好的定位(并且quotes
)。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{automata,positioning,quotes}
\begin{document}
\begin{tikzpicture}[->,shorten >=1pt,auto,node distance=2cm,
thick,main node/.style={circle,draw,font=\sffamily\large\bfseries}]
\node[main node,initial,initial text={}] (S) {$q_s$};
\node[main node] (1)[above right=of S] {$q_1$};
\node[main node] (2)[above right=of 1] {$q_2$};
\node[main node,double] (3)[above right=of 2]{$q_3$};
\node[main node] (4)[below right=of 3] {$q_4$};
\node[main node] (6)[below right=of 2] {$q_6$};
% \node[main node] (8)[below right=of 6] {$q_8$};
\node[main node] (9)[below right=of S] {$q_9$};
\node[main node] (10)[below right=of 9]{$q_a$};
\node[main node] (7)[above right=of 10] {$q_7$};
\path (6) -- node[main node,auto=false] (5) {$q_5$} (7);
\node[main node] (11)[below right=of 10]{$q_b$};
\node[main node] (12)[above right=of 11]{$q_c$};
\node[main node] (13)[above right=1cm and 3cm of 5] {$q_d$};
\node[main node] (14)[below right=1cm and 3cm of 5] {$q_e$};
\node[main node] (15)[right=of 13] {$q_f$};
\node[main node] (16)[right=of 14]{$q_g$};
%\node[main node] (16)[above right of=15] {$q_g$};
%\node[main node] (17)[below right of=15] {$q_h$};
\path[every node/.style={font=\sffamily\small}]
(S) edge["1"] (1)
edge node[below left] {0} (9)
(1) edge["0"] (5)
edge["1"] (2)
(2) edge["1"] (3)
edge["0"] (6)
(3) edge[loop above,"1"] (3)
edge[bend right,"0"'] (6)
(4) edge[loop right,"0"] (4)
edge["1"'] (3)
(6) edge [bend right,"1"] (3)
edge["0"'] (4)
(7) edge[loop above,"0"] (7)
edge[bend right,"1"] (11)
(5) edge["1"] (14)
edge["0"] (13)
(9) edge["0"] (10)
edge["1"] (5)
(10) edge["1"] (11)
edge["0"] (7)
(11) edge["1"'] (12)
edge[bend right,"0"] (7)
(12) edge [loop right,"1"] (12)
edge["0"'] (7)
(13) edge [loop above,"0"] (13)
edge["1"] (15)
(14) edge [loop below,"1"] (14)
edge["0"] (16)
(15) edge (14)
edge[bend right,"0"] (16)
(16) edge (13)
edge[bend right,"1"] (15)
;
%(16) edge[loop above] node {0} (16)
%(17) edge[loop below] node {1} (17)
\end{tikzpicture}
\end{document}