Im trying to get a table added to my exam tex file that shows the grade earned based on all possible amounts of scorable points.

I am running intwo two issues:

  1. The amount of \numpoints of the {exam} class should be the amount of loops of the table (after all: points scored will be between 0 and the max amount of points). I cannot use the \numpoints command that is builtin {exam} documentclass in the forloop however without getting errors. (In the MWE I manually entered the \numpoints amount)

  2. I cannot use for loop to generate lines of the table.


%Workaround for not being able to use exam's builtin \numpoints in the formula (bonus points for workaround)


\question[2] A Question
\question[2] A Question
\question[2] A Question
\question[2] A Question
\question[2] A Question
%nb. 10 points earnable
\foreach \n in {0,...,12 }{ \n \quad \quad  \pgfmathparse{2*\n + \manualpoints }\pgfmathresult  \par } 
\hfill \break
the above loop & in this table

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Jan 21, 2022 at 11:49
  • Welcome to TeX.SE. It is not clear exactly what you want to do. A solution would be to conditionally build the table contents before the actual tabular. It would be helpful if you composed a MWE including \documentclass and the appropriate packages that provides a small mock up of what you desire. Jan 21, 2022 at 17:36

1 Answer 1


Here is an example of building up a table where the number of rows is variable and the entry in the row is computed via the \Formula macro defined as


where #1 is the row number. This yields:

enter image description here




%% This is based on:
%%     https://tex.stackexchange.com/a/165153/4301
    %%% assignments to \@tabtoks must be global, because they are done in \foreach
        %% https://tex.stackexchange.com/a/175573/4301
    %%% variable should always be operated on either always locally or always globally

    \pgfmathprintnumber[fixed, precision=2, fixed zerofill]{\pgfmathresult}%

    % Build Required Table
    \foreach \Entry in {1,...,\Nunpoints} {%
        \eAddTableTokens{\Entry & \noexpand\Formula{\Entry} \\}%
        $n$ & Value \\
  • Thanks a ton peter, exactly what I was looking for. The only challenge I have left is if I can use the exam class' \numpoints for the amount of loops without manually filling the amount in a \newcommand. Jan 21, 2022 at 18:40
  • Your welcome. That change should be easily doable. If you get stuck please post a new question on how to get that value directly. Jan 21, 2022 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.