[Tex/LaTex] How to change the layout of the grading table in the exam document class

examtables

I'm using LuaLaTeX with the exam document class and I would like (if it's possible) to change the default layout of the grading table to be more like the tables from the booktabs package. How can I do that? I read the manual and even if the table command has many options I didn't find a way to do that. I also read a similar question about the exsheet package but the answer provided doesn't compile.

Here is a minimal working example with the tables I'd like to change at the end of it.

% !Mode:: "TeX:UTF-8"
\documentclass[a4paper,addpoints,11pt]{exam} 

\usepackage{fontspec}                    
\usepackage{polyglossia}                          

\begin{document}

\begin{questions}
\question[10]
Example question
\question[20]
Example question
\question[30]
Example question
\question[40]
Example question
\question[50]
Example question
\end{questions}

\begin{center}
\pointtable[v][questions]
\end{center}

\begin{center}
\pointtable[h][questions]
\end{center}

\end{document}

And here is the result

enter image description here

Best Answer

The building of the tables is a little bit tricky in class exams. În my eyes the horizontal table is much more better.

With the following MWE both table are changed. The needed changes you find in the part of the preamble, enclosed with \makeatletter and \makeatother.

% !Mode:: "TeX:UTF-8"
\documentclass[a4paper,addpoints,11pt]{exam} 

%\usepackage{fontspec}      % No LuaLaTeX !!!!
%\usepackage{polyglossia}   % No LuaLaTeX !!!!
\usepackage{booktabs}


% Change table layout
\makeatletter            % @ a normal letter

%first table:
\def\@vpttblquestions{%
  % Vertical non-bonus point table, indexed by questions:
  \set@hlfcntr{tbl@points}{0}%
  \begin{tabular}{cc}
%   \hline  % topline
    {\@vqword}& {\@vpword}\\
    \midrule
    \setcounter{question}{\tbl@firstq}%
    \addtocounter{question}{-1}\do@vptloop
    {\@vtword}& \prt@tablepoints\\
%    \hline  % endrule
  \end{tabular}%
}% @vpttblquestions
\def\do@vptloop{%
  % \do@vptloop is used by \@vpttblquestions
  \addtocounter{question}{1}%
  \ref{question@\arabic{question}} &
        \pointsofquestion{\arabic{question}}\\
%  \hline
  \@ifundefined{pointsofq@\romannumeral \c@question}%
    {}%
    {\addto@hlfcntr{tbl@points}
       {\csname pointsofq@\romannumeral \c@question\endcsname}}%
  \ifnum \value{question} < \tbl@lastq\relax
    \let\next@vptloop=\do@vptloop
  \else
    \let\next@vptloop=\relax
  \fi
  \next@vptloop
}% do@vptloop

% second table
\def\@htblquestions{%
  % We get here from \@tblquestions.
  % The table is horizontal and indexed by question numbers.
  % The question range has already been determined.
  % Set num@cols equal to the number of questions on the table, and
  % do either bonus, combined, or non-bonus table, in each case
  % putting in a line for scores only if it's a gradetable:
  \@ifundefined{exam@numquestions}%
  {}%
  {%
    \setcounter{num@cols}{\tbl@lastq}%
    \addtocounter{num@cols}{-\tbl@firstq}%
    \addtocounter{num@cols}{1}%
  }%
  % Do either bonus, combined, or non-bonus table.  In each case, put
  % in a line for scores if it's a gradetable:
  \begingroup
    % Save the current value of question in @iterator, so that
    % we can restore it after doing the table:
    \setcounter{@iterator}{\value{question}}%
    \renewcommand\arraystretch{\@gtblstretch}%
    \if@bonus
      % It's a horizontal bonus table, by questions:
      \begin{tabular}{l*{\thenum@cols}{c}c}
%        \hline
        {\@bhqword}& \setcounter{question}{\tbl@firstq}%
        \addtocounter{question}{-1}\do@qnumloop
        {\@bhtword}\\
%        \hline
        \set@hlfcntr{tbl@bonuspoints}{0}%
        {\@bhpword}& \setcounter{question}{\tbl@firstq}%
        \addtocounter{question}{-1}\do@bptloop
        \prt@tablebonuspoints\\
%        \hline
        % If it's a grade table, add in the score line:
        \if@scores
          {\@bhsword}& \setcounter{question}{\tbl@firstq}%
          \addtocounter{question}{-1}\do@sloop
          \\
%          \hline
        \fi
      \end{tabular}%
    \else
      \if@combined
        % It's a horizontal combined table, by questions:
        \begin{tabular}{l*{\thenum@cols}{c}c}
%          \hline
          {\@chqword}& \setcounter{question}{\tbl@firstq}%
          \addtocounter{question}{-1}\do@qnumloop
          {\@chtword}\\
%          \hline
          \set@hlfcntr{tbl@points}{0}%
          {\@chpword}& \setcounter{question}{\tbl@firstq}%
          \addtocounter{question}{-1}\do@ptloop
          \prt@tablepoints\\
%          \hline
          \set@hlfcntr{tbl@bonuspoints}{0}%
          {\@chbpword}& \setcounter{question}{\tbl@firstq}%
          \addtocounter{question}{-1}\do@bptloop
          \prt@tablebonuspoints\\
%          \hline
          % If it's a grade table, add in the score line:
          \if@scores
            {\@chsword}& \setcounter{question}{\tbl@firstq}%
            \addtocounter{question}{-1}\do@sloop
            \\
%            \hline
          \fi
        \end{tabular}%
      \else
        % Horizontal non-bonus table, indexed by question number:
        \set@hlfcntr{tbl@points}{0}%
        \begin{tabular}{l*{\thenum@cols}{c}c}
%          \hline
          {\@hqword}& \setcounter{question}{\tbl@firstq}%
          \addtocounter{question}{-1}\do@qnumloop
          {\@htword}\\
          \midrule
          {\@hpword}& \setcounter{question}{\tbl@firstq}%
          \addtocounter{question}{-1}\do@ptloop
          \prt@tablepoints\\
%          \hline
          % If it's a grade table, add in the score line:
          \if@scores
            {\@hsword}& \setcounter{question}{\tbl@firstq}%
            \addtocounter{question}{-1}\do@sloop
            \\
%            \hline
          \fi
        \end{tabular}%
      \fi
    \fi
    % Restore the saved value of question:
    \setcounter{question}{\value{@iterator}}%
  \endgroup
}% @htblquestions

\makeatother


\begin{document}

\begin{questions}
\question[10]
Example question
\question[20]
Example question
\question[30]
Example question
\question[40]
Example question
\question[50]
Example question
\end{questions}

\begin{center}
\pointtable[v][questions]
\end{center}

\begin{center}
\pointtable[h][questions]
\end{center}

\end{document} 

With the result:

enter image description here

It would be better if the author of the class would integrate two different layouts for the tables in his class.

Related Question