1

enter image description here

I want to position the nodes "Herby I invite" and "to some event at my place" vertically below of resp. above of the name but horizontally I want to set the position to 10 mm. How can I position a node relative to another in one dimension, but with a fixed value in the other dimension?

This is my 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
    Can you illustrate with some hand drawings, what you like to have? With below right=<horizontal distance> and <vertical distance> of <coordinate> you can places node where you like to have in respect to <coordinate>. – Zarko Jun 20 at 0:17
  • 1
    One solution is to specify two points A and B and use (A -| B) or (A |- B). – John Kormylo Jun 20 at 3:14
1

You just need to calculate an extra 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}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.