Ich habe folgendes Tikz-Bild:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate (origin) at (0,0) ;
\node[above=10pt of origin,anchor=east] (topnode) {Short};
\node[below=10pt of origin,anchor=east] (bottomnode) {Longer Node};
\end{tikzpicture}
\end{document}
Mein Ziel ist es, einen Knoten an der Position (x,y) zu platzieren, wobei y = 0 ist, aber x gleich dem äußersten linken der beiden Knoten (oberster Knoten) und (unterster Knoten) ist. Ich möchte dies tun, ohne die Position fest zu codieren. Damit die Position immer noch korrekt wäre, wenn ich den Inhalt dieser beiden Knoten ändern würde.
Antwort1
local bounding box
Die linken/rechten/oberen/untersten Koordinaten von allem, was sich darin befindet, sind bekannt .
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate (origin) at (0,0) ;
\begin{scope}[local bounding box=nodes]
\node[above=10pt of origin,anchor=east] (topnode) {Short};
\node[below=10pt of origin,anchor=east] (bottomnode) {Longer Node};
\end{scope}
\node[anchor=west] at (origin-|nodes.west) {here I am};
\end{tikzpicture}
\end{document}
Antwort2
Eine andere Möglichkeit: Verwenden Sie \pgfgetlastxy
:
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\newdimen\xone
\newdimen\y
\newdimen\xtwo
\begin{document}
\begin{tikzpicture}
\coordinate (origin) at (0,0) ;
\node[above=10pt of origin,anchor=east,inner sep=0pt] (topnode) {Short};
\node[below=10pt of origin,anchor=east,inner sep=0pt] (bottomnode) {Longer Node};
\path (topnode.west);
\pgfgetlastxy{\xone}{\y};
\path (bottomnode.west);
\pgfgetlastxy{\xtwo}{\y};
\draw ({min(\xone,\xtwo)},0) circle (1pt);
\end{tikzpicture}
\end{document}
Ich habe an der gewünschten Stelle einen Kreis eingefügt. Sie können ihn beliebig verändern und sogar dies als Koordinate verwenden: