I looked into this answer and tried to improve it. My goal is to get this table:
| 1 |
| 2 |
| 3 |
But instead I get this:
| 1 |
| 1 |
| 1 |
Code:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgffor}
\makeatletter
\newtoks\@tabtoks
\newcommand\addtabtoks[1]{\global\@tabtoks\expandafter{\the\@tabtoks#1}}
\newcommand*\resettabtoks{\global\@tabtoks{}}
\newcommand*\printtabtoks{\the\@tabtoks}
\makeatother
\begin{document}
\resettabtoks
\foreach \i in {1,...,3} {%
\addtabtoks{\i \\\hline}
}
\begin{tabular}{ | c | }
\hline
\printtabtoks
\end{tabular}
\end{document}
I think, it's caused by \expandafter, but I don't know, how to fix it.