![如何在乳胶中两个节点之间画一条虚线](https://linux22.com/image/409498/%E5%A6%82%E4%BD%95%E5%9C%A8%E4%B9%B3%E8%83%B6%E4%B8%AD%E4%B8%A4%E4%B8%AA%E8%8A%82%E7%82%B9%E4%B9%8B%E9%97%B4%E7%94%BB%E4%B8%80%E6%9D%A1%E8%99%9A%E7%BA%BF.png)
如何在 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}
您会标记边吗?到目前为止,节点都是空的。如果您不会,请删除它们。