2

The exam class allows one to generate a gradetable that is dynamically generated depending on the number of questions, like so

\documentclass[addpoints,12pt]{exam}
\begin{document}
\multirowgradetable{1}[questions]
\begin{questions}
    \question[10] First question
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
\end{questions}

which gives this: enter image description here

As this table is too wide, exam gives the option to display multiple tables instead:

\documentclass[addpoints,12pt]{exam}
\begin{document}
\multirowgradetable{2}[questions]
\begin{questions}
    \question[10] First question
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
\end{questions}

which produces enter image description here

I want the number of tables to be dynamically generated, so that I have a table for each 10 exercises. I tried this using the calculator package:

\documentclass[addpoints,12pt]{exam}
\usepackage{calculator}
\begin{document}
\begin{questions}
    \question[10] First question
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
\end{questions}
\INTEGERDIVISION{\numquestions}{10}{\sola}{\solb}
\ADD{\sola}{1}{\numrows}
\multirowgradetable{\numrows}[questions]
\end{document}

This works as long I put the table at the end of the document. But I want it at the beginning. What can I do to achieve this?

1 Answer 1

1

You can save the number of questions at end document in the aux file, so to allow to have the number available at the beginning of the next run.

One table is produced if the number of questions is up to eight, otherwise two tables are produced.

\documentclass[addpoints,12pt]{exam}

\makeatletter
\AtEndDocument{%
  \ifdefined\exam@numquestions
    \immediate\write\@auxout{\string\total@questions{\exam@numquestions}}%
  \fi
}
\newcommand{\total@questions}[1]{\gdef\totalquestions{#1}}
\providecommand{\totalquestions}{1}
\makeatother

\begin{document}

\multirowgradetable{%
  \ifnum\totalquestions<9 1\else 2\fi
}[questions]

\begin{questions}
    \question[10] First question
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
    \question[10] Another
\end{questions}

\end{document}

enter image description here

This is the output when only eight questions are provided.

enter image description here

1
  • This works perfectly, thank you!
    – M. E.
    Oct 15, 2022 at 11:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .