如何在 latex 中在两个节点之间画一条虚线。我使用了下面的命令,但无法用虚线连接两个节点 3 和 4。
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (1) {$1$};
\node[main node] (2) [above of=1] {$2$};
\node[main node] (3) [above of=2] {$3$};
\node[main node] (4) [above of=3] {$4$};
\path[every node/.style={font=\sffamily\small}]
(1) edge node [above] {} (2)
edge [loop left] node {} (1) (1)
(2) edge node [above] {} (3)
edge [loop left] node {} (2) (2)
(3) edge node [above] {} (4)
edge [loop left] node {} (3) (3);
\end{tikzpicture}
答案1
正如@CFG在他的评论中提到的那样,将选项添加\dotted
到边缘,该边缘应该是虚线。 我还使用了库positioning
并稍微重新排列了您的代码:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows,
positioning}
\begin{document}
\begin{tikzpicture}[auto,
node distance = 12mm,
every edge/.style = {draw, -stealth', shorten >=1pt, thick},
main node/.style = {circle,draw,font=\Large\sffamily\bfseries}
]
\node[main node] (1) {$1$};
\node[main node] (2) [above=of 1] {$2$};
\node[main node] (3) [above=of 2] {$3$};
\node[main node] (4) [above=of 3] {$4$};
%
\path[every node/.style={font=\sffamily\small}]
(1) edge node [right] {} (2)
edge [loop left] node {} ()
(2) edge node [right] {} (3)
edge [loop left] node {} ()
(3) edge [dotted] node [right] {} (4) % <---
edge [loop left] node {} ();
\end{tikzpicture}
\end{document}
您会标记边吗?到目前为止,节点都是空的。如果您不会,请删除它们。