Very similar to Correcting TikZ pattern offsets but I couldn't figure out how to do this programmatically.
Specifically, I have some nodes I'd like to use arbitrarily in text, formulae, figures, whatever, which are patterned, and I'd like them all to look the same.
Something similar to this MWE:
\documentclass[a5paper]{article}
\usepackage{lipsum}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{zref-savepos}
\usetikzlibrary{arrows,automata,patterns,patterns.meta}
\newcommand{\dotnode}[1]{
\zsavepos{#1}
\tikz[baseline = -0.5ex]{\node[state,
rectangle,
pattern={Dots[xshift={\zposx{#1} sp}, yshift={\zposy{#1} sp}, angle=45, distance={4pt}, radius=0.6pt]},
minimum size=10pt]{}}
at (\zposx{#1}, \zposy{#1})}
\begin{document}
This is a \dotnode{1} and this is another \dotnode{2}.
\lipsum[1]
This is another \dotnode{3}.
\begin{tikzpicture}
\foreach \n in {0,1,...,5}
{
\node [rectangle,draw,minimum width=1cm,minimum height=1cm,
pattern={Dots[xshift={1.1\n cm}]}] at (1.1\n cm, 1.1) {};
}
\end{tikzpicture}
\end{document}
Clearly, the dotted boxes in the text do not look the same (the bottom, good, row is from the code in the link at the top of this question).
My attempt was to use \zsavepos and use that position to xshift/yshift, and if it worked I could make the tag generation automatic, but it clearly failed. I'm not sure I understand \zsavepos correctly because the y-coordinate is the same for the first two nodes in the image, when one is clearly higher than the other (I assume the printing of \zposx/y "pushed" it?). I'm also concerned that \zsavepos would give me trouble in double column layouts which is what I am working with.

outer, I did not know about it. – mbarbar Aug 16 '20 at 07:21