我正在创作一幅tikz
由两个节点a
和组成的画b
。我想插入节点,c
使得c.x=b.x
和c.y=a.y
。请参阅下面的代码片段-
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\draw[style=help lines] (0, 0) grid (5, 5);
\node (a) [rectangle, draw, fill=red!20] at (1, 1) {Rectangle A};
\node (b) [rectangle, draw, fill=green!20] at (4, 4) {Rectangle B};
\node (c) [rectangle, draw, fill=blue!20] at (4, 1) {Rectangle C};
\end{tikzpicture}
\end{document}
以下是生成的图表-
请注意,我已经手动提到了节点的坐标c
。
如何使用let
或任何其他命令来提供使得和的calc
坐标?c.x=b.x
c.y=a.y
答案1
如果我理解正确的话它一定回答了你的问题
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\begin{document}
\begin{tikzpicture}
\draw[style=help lines] (0, 0) grid (5, 5);
\node (a) [rectangle, draw, fill=red!20] at (1, 1) {Rectangle A};
\node (b) [rectangle, draw, fill=green!20] at (4, 4) {Rectangle B};
\node (c) [rectangle, draw, fill=blue!20] at (b|-a) {Rectangle C};
\node[rectangle, draw, fill=blue!20](d) at ($(a)!0.3!(b)$) {rect D};
\node (e) [rectangle, draw, fill=blue!20] at (a|-b) {Rectangle E};
\end{tikzpicture}
\end{document}
答案2
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\draw[style=help lines] (0, 0) grid (5, 5);
\node (a) [rectangle, draw, fill=red!20] at (1, 1) {Rectangle A};
\node (b) [rectangle, draw, fill=green!20] at (4, 4) {Rectangle B};
\node (c) [rectangle, draw, fill=blue!20] at (b|-a) {Rectangle C};
\end{tikzpicture}
\end{document}