1

For an exam, each problem is named. So I would like to include the question in the grade table including question number and name left-aligned.

With the following example, the questions are centred and the question number is not included. How can I do this? Ideally, I would like to show 1. What's the difference between a duck? in the grade table.

Here is the code :

\documentclass[addpoints]{exam}

\qformat{
  \large\textbf{Question \thequestion~: \thequestiontitle}
  \quad (\thepoints)\hfill
  \vrule depth 1em width 0pt
}

\begin{document}

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

\begin{questions}
    \titledquestion{What's the difference between a duck?}[42]
    Lorem ipsum.
\end{questions}
\end{document}

enter image description here

1 Answer 1

1

Add the following lines after loading the document class.

\usepackage{regexpatch}
\makeatletter
\xpatchcmd*\@multicolumntable{|c|c|c|c}{|l|c|c|c}{}{}
\xpatchcmd\questions{\def\@currentlabel{\thequestiontitle}}{\def\@currentlabel{\thequestion. \thequestiontitle}}{}{}
\makeatother

enter image description here

\documentclass[addpoints]{exam}
\usepackage{regexpatch}
\makeatletter
\xpatchcmd*\@multicolumntable{|c|c|c|c}{|l|c|c|c}{}{}
\xpatchcmd\questions{\def\@currentlabel{\thequestiontitle}}{\def\@currentlabel{\thequestion. \thequestiontitle}}{}{}
\makeatother

\qformat{
  \large\textbf{Question \thequestion~: \thequestiontitle}
  \quad (\thepoints)\hfill
  \vrule depth 1em width 0pt
}

\begin{document}

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

\begin{questions}
    \titledquestion{What's the difference between a duck?}[42]
    Lorem ipsum.
\end{questions}
\end{document}
6
  • How do you learn about this magic? I've read the manual and didn't find anything about that. How do you know you need to use xpatchcmd?
    – nowox
    Jan 20, 2021 at 12:11
  • I have the error \xshowcmd already defined! when including regexpatch
    – nowox
    Jan 20, 2021 at 12:16
  • Regarding the error: Start from my code above and add the \usepackage commands as well as the other code of your preamble step by step and test each time, whether the error occurs. Apparently some part of you preamble already loads regexpatch or xpatch.
    – gernot
    Jan 20, 2021 at 13:31
  • 1
    Regarding the magic: (rege)xpatch is only a tool to patch macros. The command \xpatchcmd takes the name of a macro (\@multicolumntable and \questions above) and replace in its code one fragment by another one. The tricky part is to find the right patch. For this, I read the code of the package or class (here: exam.cls), try to understand the functionality, and then hopefully find a way to tweak the code such it does what we want.
    – gernot
    Jan 20, 2021 at 13:36
  • 1
    @nowox If you don't want to/can't identiy the source of the problem, you can add the line \let\xshowcmd\undefined after my lines above. \xshowcmd is defined in the package regexpatch, but none of its commands are needed after performing the two \xpatchcmd, so it is safe to undefine any conflicting macro. But of course the cleaner way would be to find the conflict and avoid loading the package twice.
    – gernot
    Jan 20, 2021 at 14:57

You must log in to answer this question.

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