是否有允许在 tikz 中使用线作为节点的语法?在以下示例中:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%dummy nodes
\node (A) at (0,0) {};
\node (B) at (5,0) {};
\node (C) at (2,-5) {};
\draw (A)--(B);
\draw (C)--(2,0);
\end{tikzpicture}
\end{document}
我想写一些诸如\draw (C)--[(A)--(B)]
而不是 的内容\draw (C)--(2,0)
。当然,在这个例子中,我明确知道节点的坐标,但在我的实际图表中我不知道,每当我添加一些改变其大小的东西时,我都必须反复试验调整显式节点的坐标。
谢谢
答案1
local bounding box=<node name>
这里您所需要的就是选项。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%dummy nodes
\node (A) at (0,0) {};
\node (B) at (5,0) {};
\node (C) at (2,-5) {};
% this creates a rectangle node named AB
\draw[local bounding box=AB] (A)--(B);
\draw (C) |- (AB);
\end{tikzpicture}
\end{document}
更新:以及投影修改器版本:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
%dummy nodes
\node (A) at (0,0) {};
\node (B) at (5,0) {};
\node (C) at (2,-5) {};
\draw (A)--(B);
% draw a line from node C to the projection of C on line A to B
% see pgfmanual, sec. 13.5.5 _The Syntax of Projection Modifiers_
\draw (C) |- ($(A)!(C)!(B)$);
\end{tikzpicture}
\end{document}