0

I quite like exam package, but in my use case, each question has a title and a number. The same as the \section of an article which has a name and a number. Thus, I would like to display the current question number/or name in the header the same way we use \rightmark. Last but not least, I would like the grade table to display the full question name.

In my case the first question is named Foo, has the number 1 and its full name is: Problem 1: Foo.

\documentclass[addpoints]{exam}

\firstpageheader{Exam}{}{}
\runningheader{Exam / Problem \thecurrentquestionnumber}{}{}

\newcounter{questioncounter}
\newcommand\thequestionnumber[1]{\thequestioncounter}

\qformat{%
  \addtocounter{questioncounter}{1}
  \large\textbf{Problem \thequestionnumber~:~\thequestiontitle}
  \quad (\thepoints)\hfill
  \vrule depth 1.5em width 0pt
}

\begin{document}

\begin{center}
    % In this table I would like the question number instead of the question name
    \gradetable[v][questions]  \vspace*{10ex}
\end{center}
  
\begin{questions}
    \newpage
    \titledquestion{Foo}[10] % Question 1
    ...\par
    \newpage
    \titledquestion{Bar}[10] % Question 2
    ...\par
    \newpage
    \titledquestion{Baz}[10] % Question 3
    ...\par

\end{questions}
\end{document}

How can I perform the following using the exam package? Where should I look at?

  1. Insert current question name/number in the header
  2. Display full name with the question number in the gradetable
  3. Deal with both question name and question number

EDIT

One possibility is to monkey patch the exam.cls by adding the following:

\newenvironment{questions}{%
  ...
  \def\@queslevel{question}%
  \def\titledquestion##1{%
    \@bonusfalse
    \def\thequestiontitle{##1}%    
    \process@question
  }%
  ...
  \def\process@question{%
    ...
    \xdef\rightmark{Problem \thenumquestions~\thequestiontitle}

But I would like to know if there is a better option...

3
  • Are you going to insert only one question per page? Observe that the header is a page header.
    – Sigur
    Dec 27, 2021 at 14:06
  • Traditionally our exams are made of 5 questions each of them corrected by one teacher. So it is very convenient to have one question per sheet (either an A4 or a double A4 sheet). Of course, each question has several parts.
    – nowox
    Dec 27, 2021 at 14:13
  • Note that LaTeX deliberately delays changing \rightmark and \leftmark so that only one change per page is allowed. You can replace that using \xdef\rightmark{...} and instead display the last value set. Dec 27, 2021 at 15:08

1 Answer 1

0

This answers most of your questions. (For future readers, you'd better ask one at a time.)

The command \qtitle deals with the first column of the grade table.

I don't know how to easily insert the "full" question name in the header. But perhaps it is redundant and the question number is sufficient.

c

d

% !TeX TS-program = pdflatex

\documentclass[addpoints]{exam}

\firstpageheader{\large Exam}{}{}
\runningheader{\large Exam / Problem \thequestion}{}{}% changed <<<<

\qformat{% changed <<<<
\large\textbf{\thequestiontitle}
\parbox{\textwidth}{\quad (\thepoints)\hfill}
\vrule depth 1.5em width 0pt
}

\newcommand{\qtitle}[1]{Problem \thequestion: \enspace  #1\hfill}% added <<<<<<<<<<<<<<

\begin{document}

\begin{center}
    \gradetable[v][questions]  \vspace*{10ex}
\end{center}

\newpage

\begin{questions}   

    \titledquestion{\qtitle{Everything}}[30] What is the answer to everything?
        \begin{solutionordottedlines}[1cm]
            42
        \end{solutionordottedlines} 
    
    \newpage
    
    \titledquestion{\qtitle{Foo}}[20] Do you know foo?
        \begin{solutionordottedlines}[1cm]
            yes
        \end{solutionordottedlines}
    
    \newpage
    
    \titledquestion{\qtitle{Bar}}[15]Do you know bar?
        \begin{solutionordottedlines}[1cm]
            yes
        \end{solutionordottedlines}
    
    \newpage
    
    \titledquestion{\qtitle{Baz}}[10] Do you know baz?
        \begin{solutionordottedlines}[1cm]
            no
        \end{solutionordottedlines} 
    
    \end{questions}

\end{document}

You must log in to answer this question.

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