I would like to generate an automatic table using loop. As suggested here before, it is best to first generate the lines in a toks and then pass them to tabular. However, I have problems with accessing the line counting variable inside the line as in the following example:
\documentclass{article}
\newcount\it
\newcount\tot
\newtoks\tablines
\def\addtomytablines#1{\tablines\expandafter{\the\tablines#1}}
\it=2
\tot=7
\loop
\addtomytablines{\the\it&&&\\\cline{2-3}}
\advance\it 1
\ifnum \it<\tot
\repeat
\def\maketable{%
\begin{tabular}{r|p{7mm}|p{7mm}|p{5mm}} \cline{2-3}
& foo & foo & \\ \cline{2-3}
\the\tablines
foofoo & & & \\ \cline{2-3}
\end{tabular}
}
\begin{document}
\maketable
\end{document}
The desired output would be that each line number starts with the current line number (so from 2 to 6), however the output is
so always writes the last value of \it.
Any ideas on what to change to make it work? Simply changing the line inside the loop to
\addtomytablines\expandafter{\the\it&&&\\\cline{2-3}}
gives the correct numbers but not a table anymore.