我学会了这些技巧:
\draw (X) -- ++(1,1); % relative positioning
\draw (X) -- (P1 |- P2);
% intersecting coordinates: the x-coordinate of P1 and the y-coordinate of P2
有没有办法用\draw
指定当前位置的内容替换上面第二个命令中的 P1?
类似完整例子:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[font=\sffamily]
\node[draw, circle](C1) at (2,2){Hey dude!};
\node[draw, circle](C2) at (3,4){C2};
\draw[thick] (C1.east) -- ++(1,1) -- (4,0 |- C2.south);
\coordinate(X) at ($(C1.east) + (1,1)$);
\draw[red,thick](X) -- (X |- C2.south);
\end{tikzpicture}
\end{document}
红色垂直线是我想要的(但我必须手动计算并定义一个坐标);旁边的黑色对角线是绘制的线-- (4,0 |- C2.south)
,我想用4,0
代表当前位置的东西来替换它。
答案1
您知道如何使用坐标。因此您可以直接说\draw[thick] (C1.east) -- ++(1,1) coordinate (y) -- (y |- C2.south);
。为了便于比较,我将代码中的红线保留为细虚线。
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[font=\sffamily]
\node[draw, circle](C1) at (2,2){Hey dude!};
\node[draw, circle](C2) at (3,4){C2};
\draw[thick] (C1.east) -- ++(1,1) coordinate (y) -- (y |- C2.south);
\coordinate(X) at ($(C1.east) + (1,1)$);
\draw[red,thin, dashed](X) -- (X |- C2.south);
\end{tikzpicture}
\end{document}