I'm trying to create a grade table. This is a follow up question to Create an array of variables. The issue is that the grading table sits below the questions. The way I want is that the questions should appear after the grading table.However, if the grading table is at the top, I will have not called any csdef commands and I won't have any output. (I've tried and this is true, of course.) So, how can I put the grading table before the actual questions.
p.s. I've tried totcount package and replaced csdefs with \newtotcounter but it gives huge number of errors which I have no clue about.
My MWE is here:
\documentclass{article}
\usepackage{etoolbox}
\newcounter{cnt}
\newcommand\addtext[1]{%
\stepcounter{cnt}%
\csdef{text\thecnt}{#1}}
\newcommand\gettext[1]{%
\csuse{text#1}}
\begin{document}
Question 1: Blah.
\addtext{3}
Question 2: Blah.
\addtext{2}
Question 3: Blah.
\addtext{4}
\begin{tabular}{ |l|c@{} *{\thecnt}{c|} } % the first row is hidden
\hline
\newcounter{colnum}%
\setcounter{colnum}{0}%
Q. No.:\hfill &
\whileboolexpr
{ test {\ifnumcomp{\value{colnum}}{<}{\thecnt}} }%
{&\stepcounter{colnum}\thecolnum}\\
\hline
Score: &
\setcounter{colnum}{0}
\whileboolexpr
{ test {\ifnumcomp{\value{colnum}}{<}{\thecnt}} }%
{&\stepcounter{colnum}\hspace{1cm}}\\
\hline
Total: &
\setcounter{colnum}{0}
\whileboolexpr
{ test {\ifnumcomp{\value{colnum}}{<}{\thecnt}} }%
{&\stepcounter{colnum}\gettext{\thecolnum}}\\
\hline
\end{tabular}
\end{document}
saveboxesand then use these after the table. As far as I know you can't have paragraph constructs in asaveboxthough, so you would need one for every question. Perhaps there is an easier way? – Roelof Spijker Jan 18 '12 at 10:25