I'm trying to draw a set of colored balls with tikz, inside some text, but I'm struggling to align the nodes with the text. Here is a minimal working example:
\documentclass{standalone}
\usepackage{tikz,xifthen}
\begin{document}
This is a set of colored balls:
{
\tikz[baseline]{%
\foreach \x/\color in {1/red,2/white,3/blue} {
\node[circle,draw,fill=\color,line width=1pt,minimum size=0.25em,anchor=base] at (\x,0) {};
\ifthenelse{\NOT 1 = \x}{\node at ({\x-0.5},0) {,};}{}
}
}
}.
\end{document}
This produces the following output:
I would like to have the circles vertically centered with the text/math. I have tried various options for the anchor, but perhaps I am missing something really simple. Any pointers would be appreciated.




(\x,0), but instead calculate the vertical midpoint? – vikraman Feb 28 '24 at 10:45