如何获取 tikz/PGF 坐标的一个分量?
我正在尝试在图表上画一条水平线。直线的 Y 坐标应位于 a 点和 b 点之间的中间(a 在 b 下方)。线的左右端点位于 tikzpicture 的边界框上。下面是我现在使用交集运算符执行此操作的方法:
\coordinate (h0) at ($(a.north)!0.5!(b.south)$); \draw (h0 -| current bounding box.west) -- (h0 -| current bounding box.east);
这让我觉得相当迂回。我宁愿做的是获取(h0)的Y坐标和边界框东西两侧的X坐标,并自己组合坐标。我想这样做,但它不受支持的语法:
\coordinate (h0) at ($(a.north)!0.5!(b.south)$); \draw (current bounding box.west.x,h0.y) -- (current bounding box.east.x,h0.y);
有没有办法引用我缺少的坐标的各个组件?
I'm trying to draw a horizontal line across my diagram. The Y coordinate of the line should be halfway between points a and b (a is below b). The left and right endpoints of the line are on the bounding box of the tikzpicture. Here's how I'm doing this now, using the intersection operator:
\coordinate (h0) at ($(a.north)!0.5!(b.south)$); \draw (h0 -| current bounding box.west) -- (h0 -| current bounding box.east);
This strikes me as rather roundabout. What I'd rather do is get the Y coordinate of (h0) and the X coordinates of the east and west sides of the bounding box, and compose the coordinates myself. I'd like to do this, but it isn't supported syntax:
\coordinate (h0) at ($(a.north)!0.5!(b.south)$); \draw (current bounding box.west.x,h0.y) -- (current bounding box.east.x,h0.y);
Is there a way to reference individual components of coordinates that I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在
let
操作中获取组件。在 PGF 手册中查找它的工作原理,但从记忆中:这可能需要调试... 编辑:现在感谢提问者。
You can get at the components inside a
let
operation. Look it up in the PGF manual for the works, but from memory:That'll probably need debugging... EDIT: and now has been thanks to the questioner.
或者,使用
这些是原始 PGF 命令,因此使用它们可能不太方便。
Alternatively, use
These are raw PGF commands, so it may be less convenient to use them.
我刚刚从 this 找到的另一个选项表明,您可以通过以下方式从节点获取相对定位这样做:
这将从节点 a 到点 a 右侧 2 个单位的点绘制一条线。就像我链接的示例一样,当您不知道节点的确切坐标并且需要绘制相对于它的事物时,这非常有用。
Another option I just found from this shows that you can get relative positioning from a node by doing this:
This will draw a line from node a to the point 2 units to the right of point a. Like in the example I linked, this is useful when you don't know the exact coordinates of a node, and need to draw things relative to it.