mbarbar
I have some nodes I'd like to use arbitrarily inline in text, in formulae, and in figures. These nodes are patterned and I'd like them to all look the same.

So something really similar to this contrived example:

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


The output is

Clearly, the dotted boxes in the text do not look the same (the bottom, good, row is from the code in this answer: https://tex.stackexchange.com/a/545846/222516).

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. Perhaps I don't 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 in the second compilation pass?). I'm also concerned that \zsavepos would give me trouble in double column layouts which is what I am actually working with.
marmot
Your approach is completely correct except that the current version of the dots is not "movable" easily since they first rotate and then shift. In the lowest row you do not rotate, so everything is cool, but if you were to rotate the pattern there, you'd have the same problems. So you may want to first shift and then rotate, so we can just follow the [post you link to](https://tex.stackexchange.com/a/545846) and define, for the time being, a "movable" version of the Dots pattern. Starting from pgf version 3.1.6 this should not be necessary any more.


\documentclass{article}
\usepackage{lipsum}
%\usepackage{pgf}
\usepackage{tikz}
\usepackage{zref-savepos}

\usetikzlibrary{arrows,automata,patterns,patterns.meta}

\pgfdeclarepattern{
name=Movable Dots,
parameters={
\pgfkeysvalueof{/pgf/pattern keys/distance},
\pgfkeysvalueof{/pgf/pattern keys/angle},
\pgfkeysvalueof{/pgf/pattern keys/xshift},
\pgfkeysvalueof{/pgf/pattern keys/yshift},
},
bottom left={%
\pgfpoint
{-.5*(\pgfkeysvalueof{/pgf/pattern keys/distance})}%
{-.5*(\pgfkeysvalueof{/pgf/pattern keys/distance})}},
top right={%
\pgfpoint
{.5*(\pgfkeysvalueof{/pgf/pattern keys/distance})}%
{.5*(\pgfkeysvalueof{/pgf/pattern keys/distance})}},
tile size={%
\pgfpoint
{\pgfkeysvalueof{/pgf/pattern keys/distance}}%
{\pgfkeysvalueof{/pgf/pattern keys/distance}}},
tile transformation={%
\pgftransformshift{%
\pgfpoint
{\pgfkeysvalueof{/pgf/pattern keys/xshift}}%
{\pgfkeysvalueof{/pgf/pattern keys/yshift}}}%
\pgftransformrotate{\pgfkeysvalueof{/pgf/pattern keys/angle}}},
defaults={
distance/.initial=3pt,
angle/.initial=0,
xshift/.initial=0pt,
yshift/.initial=0pt,
},
code={%
\pgfpathcircle%
{\pgfpointorigin}%
\pgfusepath{fill}%
},
}

\newcommand{\dotnode}[1]{
\zsavepos{#1}
\tikz[baseline = -0.5ex]{\node[state,
rectangle,
pattern={Movable Dots[xshift={\zposx{#1} sp}, yshift={\zposy{#1} sp},
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}


![Screen Shot 2020-08-20 at 12.02.27 AM.png](/image?hash=5cda9dbebe44673d6dee65edc61d5b8abc7a59b0ad5963032fd4b7efe5ddcc32)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.