节点位置在一个维度上是相对的,但在另一个维度上是固定的

节点位置在一个维度上是相对的,但在另一个维度上是固定的

在此处输入图片描述

我想垂直定位节点“我邀请你参加”和“到我家参加某个活动”低于分别以上名称,但水平方向我想将位置设置为10 mm。如何在一个维度上将一个节点相对于另一个节点定位,但在另一个维度上使用固定值?

这是我的 MWE:

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[x=1mm,y=1mm]
\clip (0,0) rectangle (154,111);
\node[draw] at (77,55.292) (name) {\LARGE Name of a Person};
\node[draw,align=left, above of=name, anchor=west] {Herby I invite};
\node[draw,align=left, below of=name, anchor=west] {to some event at my place};
\node[draw,align=left, anchor=west] at (10,30) (sender) {Yours Me};
\node[draw,align=left, anchor=west,yshift=-1cm] at (sender.south west) {My Place};
\end{tikzpicture}
\end{document}

答案1

您只需要计算一个额外的xshift

\documentclass[tikz, border=1cm]{standalone}
\makeatletter
\newlength\coor@x
\newlength\coor@y
\def\extract@xy#1{
  \path (#1);
  \pgfgetlastxy{\coor@x}{\coor@y}
}
\tikzset{
  test/.code args={#1 at #2}{
    \extract@xy{#1}
    \pgfkeysalso{xshift={#2-\coor@x}}
  }
}
\makeatother

\begin{document}
\begin{tikzpicture}[x=1mm,y=1mm]
\clip (0,0) rectangle (154,111);
\node[draw] at (77,55.292) (name) {\LARGE Name of a Person};
\node[draw,align=left, above of=name, anchor=west, test=name at 10mm] {Herby I invite};
\node[draw,align=left, below of=name, anchor=west, test=name at 10mm] {to some event at my place};
\node[draw,align=left, anchor=west] at (10,30) (sender) {Yours Me};
\node[draw,align=left, anchor=west,yshift=-1cm] at (sender.south west) {My Place};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容