在 TikZ 中繪製路徑圖時遇到困難

在 TikZ 中繪製路徑圖時遇到困難

作為一個學習 TikZ 的初學者,我嘗試過以下方法:

\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata, positioning}

\begin{document}
\begin{tikzpicture} [draw=black,
node distance = 3cm, 
on grid, 
auto,
every loop/.style={stealth-}]

\node (e1) [state] {$E$};
\node (c1) [state, right = of e1] {$C$};
\node (a1) [state, right = of c1] {$A$};
\node (t1) [state, below = of c1] {$T1$};
\node (a2) [state, right = of a1] {$A$};
\node (c2) [state, right = of a2] {$C$};
\node (e2) [state, right = of c2] {$E$};    
\node (t2) [state, below = of c2] {$T2$};

% Arrows
\path [-stealth, thick]
(e1) edge node {$e^2$}   (t1)
(c1) edge node {$c^2$}   (t1)
(a1) edge node {$h^2$}   (t1)
(e1) edge [loop above]  node {1}()
(c1) edge [loop above]  node {1}()
(a1) edge [loop above]  node {1}()
(e2) edge node {$e^2$}   (t2)
(c2) edge node {$c^2$}   (t2)
(a2) edge node {$h^2$}   (t2)
(e2) edge [loop above]  node {1}()
(c2) edge [loop above]  node {1}()
(a2) edge [loop above]  node {1}()
(a1) edge [bend left]  node {1}(a2)
(c1) edge [bend left]  node {1}(c2);
\end{tikzpicture}
\end{document}

這是目前的結果:

在此輸入影像描述

需要改進:

  1. 將兩條彎曲路徑改為帶有雙向箭頭的;
  2. 將較長的彎曲路徑抬高一點以避免重疊;
  3. 將底部兩個節點T1、T2由圓形改為長方形;
  4. 水平對齊這六個標籤(e^2、c^2、h^2、...)。

謝謝!

答案1

幹得好!

改進後的自動機

\documentclass[border=0.2cm]{standalone}
% https://tex.stackexchange.com/questions/678743/struggling-in-drawing-a-path-graph-in-tikz

\usepackage{tikz}
\usetikzlibrary{automata, positioning}

\begin{document}
\begin{tikzpicture} [draw=black,
node distance = 3cm, 
on grid, 
auto,
every loop/.style={stealth-},
myrect/.style={rectangle,draw,inner sep=8pt}]

\node (e1) [state] {$E$};
\node (c1) [state, right = of e1] {$C$};
\node (a1) [state, right = of c1] {$A$};
\node (t1) [myrect, below = of c1] {$T1$};
\node (a2) [state, right = of a1] {$A$};
\node (c2) [state, right = of a2] {$C$};
\node (e2) [state, right = of c2] {$E$};    
\node (t2) [myrect, below = of c2] {$T2$};

% Arrows
\path [-stealth, thick]
(e1) edge node[midway,right=3pt] {$e^2$}   (t1)
(c1) edge node[midway,right] {$c^2$}   (t1)
(a1) edge node[midway,right] {$h^2$}   (t1)
(e1) edge [loop above]  node {1}()
(c1) edge [loop above]  node {1}()
(a1) edge [loop above]  node {1}()
(e2) edge node[midway,right] {$e^2$}   (t2)
(c2) edge node[midway,right] {$c^2$}   (t2)
(a2) edge node[midway,right=2pt] {$h^2$}   (t2)
(e2) edge [loop above]  node {1}()
(c2) edge [loop above]  node {1}()
(a2) edge [loop above]  node {1}()
(a1) edge [<->,bend left]  node {1}(a2)
(c1) edge [<->,bend left=50]  node {1}(c2);
\end{tikzpicture}
\end{document}

相關內容