使用考试类别,我想识别前一个问题编号。
例如当您有 3 个问题时。
第一季度 第二季度 第三季度
我想在 Q1 和 Q2 之间插入一段代码,该代码的结果将显示the previous question is 1
。
同样,在 Q2 和 Q3 之间代码将显示the previous question is 2
。
如果您尝试将代码放在最后一个问题之后,代码将会显示end of question
。
我有我的 MWE:
\documentclass[10pt,addpoints]{exam}
\begin{document}
\begin{questions}
\question[1] This is Q1.\\
\textbf{The previous question was 1.} % This is what to figure out.
\question This is Q2
\begin{parts}
\part[1] Q2 Part a
\end{parts}
\textbf{The previous question was 2.}
\question[1] This is Q3.\\
\textbf{The previous question was 3.}
\question This is Q4
\begin{parts}
\part
\begin{subparts}
\subpart[1]
\end{subparts}
\end{parts}
\textbf{The previous question was 4.}
\question[1] This is Q5.\\
\textbf{The previous question was 5.}
\end{questions}
\end{document}
我已用粗体突出显示我想要的结果。
答案1
\documentclass[10pt,addpoints]{exam}
\newcommand{\lastquestion}{%
% The class exam writes the definition of \exam@numquestions
% in the .aux file. In the first LaTeX run, \numquestions sees
% that \exam@numquestions is missing and expands to \mbox{...??}
% that breaks \ifnum.
\ifcsname exam@numquestions\endcsname
\ifnum\value{question}<\numquestions\relax
\thequestion
\else
end of question%
\fi
\else
\thequestion
\fi}
\begin{document}
\begin{questions}
\question[1] This is Q1.\\
\textbf{The previous question was \lastquestion.}
\question This is Q2
\begin{parts}
\part[1] Q2 Part a
\end{parts}
\textbf{The previous question was \lastquestion.}
\question[1] This is Q3.\\
\textbf{The previous question was \lastquestion.}
\question This is Q4
\begin{parts}
\part
\begin{subparts}
\subpart[1]
\end{subparts}
\end{parts}
\textbf{The previous question was \lastquestion.}
\question[1] This is Q5.\\
\textbf{The previous question was \lastquestion.}
\end{questions}
\end{document}