I am trying to create a template sort of LaTeX document for myself where I can set a number near the beginning (like a variable) and later in the document there shall be a table with as many rows as that number. Also, in the first column there shall be an increasing list of numbers. So if I set the 'variable' to 5, I would get a table with numbers from 1 to 5 in the first column.
I have followed this professional's answer to a similar question to create this table using tokens. My problem is that I can't get the numbers in my first column like I desire. Here is an MWE
\documentclass{article}
\def\numberoflines{10}
\newcounter{i}
\setcounter{i}{0}
\newtoks\tabtoks
\newcommand*\addtabtoks[1]{\tabtoks\expandafter{\the\tabtoks#1}}
\newcommand*\resettabtoks{\tabtoks{}}
\newcommand*\printtabtoks{\the\tabtoks}
\begin{document}
\resettabtoks
\loop\ifnum\thei<\numberoflines
\addtabtoks{\thei & \\ \hline}
\stepcounter{i}
\repeat
\begin{tabular}{| c | c |}
\hline
number & empty \\
\hline
\printtabtoks
\end{tabular}
\end{document}
yes, I know vertical lines are ugly; this is a special use case, not for professional typesetting, please ignore
Output:
Is there some fix to get 1-10 instead of 10 everywhere?
Thanks in advance!