[Tex/LaTex] Possible to combine “…” and “x/y” in TikZ’s foreach

loopstikz-pgf

I'll start with a simple, minimal non-working example:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x/\y in {1/20,2/18,...,10/2}
  \node at (\x,0) {\y};
\end{tikzicture}
\end{document}

The point, as you probably understand from the example, is to iterate over two variables at the same time that change by the same amount for each run, without having to write out all the x/y pairs explicitly. Had this worked, the expected output would be

enter image description here

but the compilation halts with an Illegal unit of measure ... error. I know the manual doesn't say anything about it, so I'm kind of expecting the answer to simply be "no, not possible". Am I missing something obvious, or is this something that TikZ can't do?

(By the way, I haven't come across a situation where I've needed this, it's just something that I came to wonder about. And I could do the loop with something else, e.g., Lua, anyway.)

Best Answer

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach[count=\i] \txt in {20,18,...,2}
  \node at (\i,0) {\txt};
\end{tikzpicture}
\end{document}

Note: It is always possible to cauculate one variable using the other one. Or you can't use ... in pgffor. So you can also use:

\begin{tikzpicture}
\foreach[evaluate=\y using int(22-2*\x)] \x in {1,...,10}
  \node at (\x,0) {\y};
\end{tikzpicture}