I'd like to generate an empty table, with underlines in the cells for someone to fill out by hand. I can generate a blank table row with a loop without issue, but once I try to add some cmidrules
to the row, the behaviour does not go as expected. My loop seems to add the very last cmidrule
, but I actually overwrite it with the last expression in the genrow
command.
The image below shows what I'm trying to generate, the red lines are what'd missing but what I expect to draw.
\documentclass{scrartcl}
\usepackage{booktabs}
\newcounter{iter} \setcounter{iter}{0}
\newtoks\tabRtok % token for table row
\newcommand\addtabRtok[1]{\tabRtok\expandafter{\the\tabRtok#1}}
\newcommand*\resettabRtok{\tabRtok{}}
\newcommand*\printtabRtok{\the\tabRtok}
\newcounter{itb} \setcounter{itb}{0}
\newcommand{\genrow}[1]{ % generates a row
\newcounter{cols}
\setcounter{cols}{#1}
\addtocounter{cols}{-1}
\resettabRtok
\setcounter{iter}{0}
\loop\ifnum\theiter<\value{cols}
\stepcounter{iter}
\addtabRtok{. & .}
\repeat
\addtabRtok{\\}
\addtabRtok{\cmidrule(r){1-1}}
\setcounter{iter}{2} %
\loop\ifnum\value{iter}<#1
\addtabRtok{\cmidrule(lr){\the\value{iter}-\the\value{iter}}} % THIS ONLY GENERATES cmidrule on last column...?
% \addtocounter{iter}{1} % this doesn't work
\stepcounter{iter}
\repeat
\addtabRtok{\cmidrule(l){#1-#1}}
}
\begin{document}
\genrow{4}
\begin{tabular}{llll}
\toprule
\printtabRtok
\bottomrule
\end{tabular}
\end{document}
\the\value{iter}
is not expanded when you add it to your token register.