我有这个自动机,需要在 LaTeX 中重现它:
到目前为止我已经有了这个,但我有点不知道如何定位边缘。
\begin{figure}[htbp]
\centering
\begin{tikzpicture}[->,>=stealth',shorten >=5pt,auto,node distance=2.8cm,semithick]
\node[state] (q0) {$q_a$};
\node[state] (q1) [above,right of=q0] {$q_b$};
\node[state] (q2) [right of=q1] {$q_c$};
\path (q0) edge [loop left] node {a} (q0);
(q1) edge [loop right] node {b} (q1);
(q2) edge [loop right] node {c} (q2);
\end{tikzpicture}
\caption{Beispiel für einen NSA/DSA}
\end{figure}
例如如何移动节点?
答案1
像这样?
\documentclass[tikz,
border=3mm
]{standalone}
\usetikzlibrary{arrows, automata,
quotes,
positioning
}
\begin{document}
\begin{tikzpicture}[
node distance = 12mm and 22mm,
every edge/.style = {draw, -stealth', shorten >=1pt},
every edge quotes/.style = {inner sep=1pt, auto},
semithick
]
\node (q0) [state] {$q_a$};
\node (q1) [state,above right=of q0] {$q_b$};
\node (q2) [state,below right=of q0] {$q_c$};
%
\path (q0) edge [loop left,"$a$"] (q0)
(q1) edge [loop right,"$b$"] (q1)
(q2) edge [loop right,"$c$"] (q2)
%
(q0.45) edge [bend left,"$b$"] (q1.180)
(q1.210) edge [bend left,"$a$"] (q0.30)
%
(q0.330) edge [bend left,"$c$"] (q2.150)
(q2.180) edge [bend left,"$a$"] (q0.300)
%
(q1.285) edge [bend left,"$c$"] (q2.75)
(q2.105) edge [bend left,"$b$"] (q1.265)
;
\end{tikzpicture}
\end{document}
节点位置由 TikZ 库确定positioning
,边的标签则使用 TikZ 库quotes
。