我想闭合双线的末端。据我所知,Tikz 没有提供内置选项。实现此目的的最佳方法是什么,包括分叉双线?(也许使用条形箭头?)
下面是一个示例代码。我在第二行手动关闭了结尾。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
%A double line with ends are not closed
\begin{tikzpicture}
\draw[line width = 2mm, double distance = 4mm] (0,0) -- (10cm,10cm);
\end{tikzpicture}
%A double line with ends are closed - manually created
\begin{tikzpicture}
\draw [line width = 8mm] (0,0) -- (10cm, 10);
\draw [line width = 4mm, white] (1.41mm,1.41mm) -- (10cm-1.41mm, 10cm-1.41mm);
\end{tikzpicture}
\end{document}
更新:根据提供的答案,我想强化我的问题如下:分叉(交叉、相交)双线怎么样?我提供了一个简单但无效的解决方案。有没有更强大的解决方案?
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
%Double lines with ends are closed with "line cap=rect"
\begin{tikzpicture}
\draw[line width = 2mm, double distance = 4mm, line cap=rect] (0,0) -- (10cm,0cm);
\draw[line width = 2mm, double distance = 4mm, line cap=rect] (5cm,0cm) -- (7cm,5cm);
\end{tikzpicture}
%Forked (Crossed) double lines
\begin{tikzpicture}
\draw[line width = 2mm, double distance = 4mm, line cap=rect] (5cm,0cm) -- (7cm,5cm);
\draw[line width = 2mm, double distance = 4mm, line cap=rect] (0,0) -- (10cm,0cm);
\draw[line width = 4mm, white] (5cm,0cm) -- (7cm,5cm);
\end{tikzpicture}
\end{document}
答案1
有line cap=round
和line cap=rect
。默认值为line cap=butt
。这些都是可能的情况 --- PDF 标准仅提供这三种。(请参阅8.4.3.3 线帽样式)
钛钾Z 确实提供了生成不同 的可能性line cap
。例如,所有箭头尖端都可以归类为line cap
s。
\documentclass[tikz,border=9]{standalone}
\begin{document}
%A double line with ends are not closed
\begin{tikzpicture}
\draw[line width = 2mm, double distance = 4mm] (0,0) -- (10cm,10cm);
\end{tikzpicture}
%A double line with ends are closed - manually created
\begin{tikzpicture}
\draw[line width = 2mm, double distance = 4mm,line cap=round] (0,0) -- (10cm,10cm);
\end{tikzpicture}
\begin{tikzpicture}
\draw[line width = 2mm, double distance = 4mm,line cap=rect] (0,0) -- (10cm,10cm);
\end{tikzpicture}
\end{document}
回答新问题
解决方案比您想象的要简单。
\begin{tikzpicture}
\draw[line width = 2mm, double distance = 4mm,line cap=rect](0,0)--(10,0)(5,0)--(7,5);
\end{tikzpicture}
好吧...我知道有人会说它很丑。所以让我重复一下。
\begin{tikzpicture}
\draw[line width = 2mm, double distance = 4mm,line cap=rect](0,0)--(10,0)(7,5)--(5,0)--(7,5);
\end{tikzpicture}
警告!风险自负
目前line cap
定义如下(tikz.code.tex
第 105 行)
\tikzoption{line cap}{\tikz@addoption{\csname pgfset#1cap\endcsname}}
可以通过以下方式覆盖它/.is choice
。钾Z 手册实际上提到了这一点。(它一直让我感到惊讶。)
有趣的是,作者把butt
和的意思互换了round
。猜猜他是故意这么做的。
还有一件事
目前,箭头尖端放在最后一条子路径的两端。另一方面line cap
,如上所示,s 放在子路径的每个端点。也许可以设法配置箭头尖端的行为。但随后需要为 编写一个解析器\draw[arrows={<-> <->}]...
。