是否可以将两条相互重叠的路径的虚线对齐?
c
下图中,由于两条路径相互重叠,节点正下方的路径部分虚线长度略密。有什么方法可以避免这种情况吗?
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw] at (-1,-1) (a) {a} ;
\node[draw] at (0,-1) (b) {b} ;
\node[draw, anchor=south] at (1,0) (c) {c} ;
\draw[dashed, ->] (c.south) |- (b.east) ;
\draw[dashed, <-] (a.south) -- +(270:3mm) -| (c.south);
\end{tikzpicture}
\end{document}
a
如果我增加从节点到的垂直调整,+(270:10mm)
这样看起来会更好,但当然调整太大了。
答案1
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw] at (-1,-1) (a) {a} ;
\node[draw] at (0,-1) (b) {b} ;
\node[draw, anchor=south] at (1,0) (c) {c} ;
\draw[dashed, ->] (c.south) |-coordinate(aux) (b.east) ;
\draw[dashed, <-] (a.south) -- +(270:3mm) -| (aux);
\end{tikzpicture}
\end{document}
答案2
以下代码展示了另一种构造方法,其结果也有所不同。在本例中,首先绘制节点 c 和 a 之间的线,然后绘制此路径与节点 b 之间的线。没有辅助节点,并且此路径的任何部分都不会绘制两次。
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw] at (-1,-1) (a) {a} ;
\node[draw] at (0,-1) (b) {b} ;
\node[draw, anchor=south] at (1,0) (c) {c} ;
\draw[dashed, ->] (c) |- ([yshift=-3mm]a.south)--(a);
\draw[dashed, <-] (b) -- (b-|c);
\end{tikzpicture}
\end{document}