![双线显示为矩形](https://linux22.com/image/395671/%E5%8F%8C%E7%BA%BF%E6%98%BE%E7%A4%BA%E2%80%8B%E2%80%8B%E4%B8%BA%E7%9F%A9%E5%BD%A2.png)
答案1
答案2
由于这是一个重复的问题,因此这里有一个装饰,它将双线绘制为两条路径,而不是一条粗线,顶部有一条白线,这就是为什么你会在两端看到细线(我认为对于某些观众来说)。语法很简单,
\draw[alt double,alt double distance=2mm] (x) -- (y);
并且也适用于曲线,参见
\draw[alt double,alt double distance=2mm] (y) to[out=90,in=180] (z);
这是代码。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations,positioning}
\pgfkeys{/tikz/.cd,
alt double distance/.initial=5pt,
alt double step/.initial=1pt,
}
\pgfdeclaredecoration{double deco}{initial}
{% initial arrow butt
\state{initial}[width=\pgfkeysvalueof{/tikz/alt double step},next state=cont] {
\pgfmoveto{\pgfpoint{\pgfkeysvalueof{/tikz/alt double step}}{\pgfkeysvalueof{/tikz/alt double distance}/2}}
\pgfpathlineto{\pgfpoint{0.3\pgflinewidth}{\pgfkeysvalueof{/tikz/alt double distance}/2}}
\pgfpathmoveto{\pgfpoint{0.3\pgflinewidth}{-\pgfkeysvalueof{/tikz/alt double distance}/2}}
\pgfpathlineto{\pgfpoint{1pt}{-\pgfkeysvalueof{/tikz/alt double distance}/2}}
\pgfcoordinate{lastup}{\pgfpoint{1pt}{\pgfkeysvalueof{/tikz/alt double distance}/2}}
\pgfcoordinate{lastdown}{\pgfpoint{1pt}{-\pgfkeysvalueof{/tikz/alt double distance}/2}}
}
\state{cont}[width=\pgfkeysvalueof{/tikz/alt double step}]{
\pgfmoveto{\pgfpointanchor{lastup}{center}}
\pgfpathlineto{\pgfpoint{\pgfkeysvalueof{/tikz/alt double step}}{\pgfkeysvalueof{/tikz/alt double distance}/2}}
\pgfcoordinate{lastup}{\pgfpoint{\pgfkeysvalueof{/tikz/alt double step}}{\pgfkeysvalueof{/tikz/alt double distance}/2}}
\pgfmoveto{\pgfpointanchor{lastdown}{center}}
\pgfpathlineto{\pgfpoint{\pgfkeysvalueof{/tikz/alt double step}}{-\pgfkeysvalueof{/tikz/alt double distance}/2}}
\pgfcoordinate{lastdown}{\pgfpoint{\pgfkeysvalueof{/tikz/alt double step}}{-\pgfkeysvalueof{/tikz/alt double distance}/2}}
}
\state{final}[width=0pt]
{ % perhaps unnecessary but doesn't hurt either
\pgfmoveto{\pgfpointdecoratedpathlast}
}
}
\tikzset{alt double/.style={decorate,decoration=double deco}}
\begin{document}
\begin{tikzpicture}
\node (x) {X};
\node[above right=1mm and 2mm of x] (y) {Y};
\draw[alt double,alt double distance=2mm] (x) -- (y);
\node[above right=1cm and 2cm of y] (z) {Z};
\draw[alt double,alt double distance=2mm] (y) to[out=90,in=180] (z);
\end{tikzpicture}
\end{document}
使用这种装饰也应该允许计算与双线的交点。