3

I have the following tikz picture:

\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}

My goal is to place a node at position (x,y), with y=0, but with x equal to leftmost of the two nodes (topnode) and (bottomnode). I would like to do this without hard-coding the position. So that the position would still be correct if I changed the content of those two nodes.

3

A local bounding box known the left/right/top/bottom-most coordinate of everything that's inside.

\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}

enter image description here

3

A different way: use the \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}

I put a circle to the desired place. You can change it to whatever you want, you can even use this as a coordinate:

enter image description here

enter image description here

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.