我想测量两个节点A
和之间的水平距离B
,然后放置另一个Y
与水平距离相同X
但与垂直对齐的节点v0
。
它的语法是什么?
更新:这是文本我想保持不变。我可以用 Paul Gaborit 的答案稍微修改一下来测量距离,但我该如何放置Y
才能Y.west
与对齐p
?
更新2:解决方法是放到[anchor=west]
节点上。
\documentclass[varwidth,margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node (v3) at (0,2) {};
\node (v2) at (0,1.5) {};
\node (v1) at (0,.5) {};
\node (v0) at (0,0) {};
\node (h1) at (1,0) {};
\node (h2) at (1.5,0) {};
\node (A) at (v3) {A};
\node (B) at (h1|-v2) {B};
\node (X) at (h2|-v1) {XXXXX};
\coordinate (p) at ($(X.east)+($(B.west)-(A.east)$)$);
\node[anchor=west](Y) at (p |- v0) {YYYYY};
\end{tikzpicture}
\end{document}
答案1
您可以使用该calc
库:
\documentclass[varwidth,margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node (v3) at (0,2.5) {};
\node (v2) at (0,1.5) {};
\node (v1) at (0,.5) {};
\node (v0) at (0,0) {};
\node (h1) at (1,0) {};
\node (h2) at (1.5,0) {};
\node (A) at (v3) {A};
\node (B) at (h1|-v2) {B};
\node (X) at (h2|-v1) {X};
\coordinate (p) at ($(X)+($(B)-(A)$)$);
\node(Y) at (p |- v0) {Y};
\end{tikzpicture}
\end{document}