I'm trying to find the minimum x coordinate in a set of TikZ coordinates.
Consider this code
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\newdimen\x
\newdimen\xmin
\xmin=10000pt
\newdimen\y
\begin{document}
\begin{tikzpicture}[every node/.style={draw}]
\node (1) {182};
\node[below=of 1] (2) {183731468};
\node[below=of 2] (3) {74632};
\path (1.west); \pgfgetlastxy{\x}{\y}
\ifdim\x<\xmin \xmin=\x \fi
\fill[red] (\xmin,\y) circle (1pt);
\path (2.west); \pgfgetlastxy{\x}{\y}
\ifdim\x<\xmin \xmin=\x \fi
\fill[red] (\xmin,\y) circle (1pt);
\path (3.west); \pgfgetlastxy{\x}{\y}
\ifdim\x<\xmin \xmin=\x \fi
\fill[red] (\xmin,\y) circle (1pt);
\end{tikzpicture}
\end{document}
and this code
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\newdimen\x
\newdimen\xmin
\xmin=10000pt
\newdimen\y
\begin{document}
\begin{tikzpicture}[every node/.style={draw}]
\node (1) {182};
\node[below=of 1] (2) {183731468};
\node[below=of 2] (3) {74632};
\foreach \i in {1,2,3} {
\path (\i.west); \pgfgetlastxy{\x}{\y}
\ifdim\x<\xmin \xmin=\x \fi
\fill[red] (\xmin,\y) circle (1pt);
}
\end{tikzpicture}
\end{document}
These are the outputs of the first code (left) and the second code (right) side by side:
Look at the dot at the bottom. The first code gives the intended output, but the second doesn't.
Why? And how to modify the \foreach loop in the second code so that it gives the same output as the first?




\draw[blue] ...renders only the...but not every other path blue. Likewise, if you say\tikz[blue]{....}everything in thetikzpicturewill be blue, but not outside, and so on.) In TeX all macros are local unless you explicitly make them global. – Apr 14 '19 at 14:56