tikz 内部节点定位

tikz 内部节点定位

我正在创作一幅tikz由两个节点a和组成的画b。我想插入节点,c使得c.x=b.xc.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.xc.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}

相关内容