4

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

1
  • I tried to look into the exam.cls file but I don't know how to modify it. Seen as nobody answered I think I'll have to give up and keep the standard layout...
    – Emmet
    Commented Oct 10, 2013 at 10:19

1 Answer 1

5

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.

7
  • How can I change the language in Italian? thanks a lot! ;)
    – ryuk
    Commented Dec 26, 2015 at 11:41
  • 1
    @ryuk it depends if you compile with pdflatex or lualatex or other. For pdflatex use package babel.
    – Mensch
    Commented Dec 31, 2015 at 13:08
  • @Mensch , how could you change the columns order? thanks in advance Commented Dec 7, 2020 at 19:43
  • 1
    @MamounMohammed Please ask a new question and explain better what you mean with "change the colums order" ...
    – Mensch
    Commented Dec 7, 2020 at 21:25
  • When I am compiling your code (either pdfLaTeX or with LuaLaTeX), I do not get the result you have – I have the same tables as usual (i.e. unchanged). How is that possible?
    – Watson
    Commented Jan 14, 2021 at 7:42

You must log in to answer this question.

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