我正在尝试使用 tikz 向两个坐标添加偏移量,如下所示:
\draw[line width=4] (coorda) ++(0.3pt,0) -- (coordb) ++(-0.3pt,0);
第一个 ++ 指令工作正常,但第二个指令无效。问题是粗水平线与垂直线不齐平(此图中显示 coordb):
我查看了文档,但还是搞不懂。如果解决方案不简单,我会提供 MWE。也许有更好的方法来连接这些线,而不依赖于手动添加偏移量?
答案1
++
指令是笔指令(PostScript 术语)。它的作用是抬起笔并移动一定距离到当前点。Single+
是另一个指令,但最终笔会回到当前点。
所以实际上你正在做的事情是
\draw[line width=4] % Set pen properties
(coorda) % move to coorda labeled point. This is the current point now.
++(0.3pt,0) % move the pen 0.3pt to the right relative to coorda
-- %put the pen down
(coordb) % draw the line. This is the current point now.
++(-0.3pt,0) % lift the pen and move 0.3pt to the left relative to coordb,
% if there was a -- here it would still draw it
; % we are done
相反,你可以单独移动这些点,例如
\draw[line width=4] ([xshift=0.3pt]coorda) -- ([xshift=-0.3pt]coordb);