我一直在尝试修改从以下获得的代码 用于计算小计 Tex 问题的宏。
我的 MWE 提出了不太好的解决方案。
\documentclass[addpoints]{exam}
%%%%%%%%%%%%%%% Finds subtotal of all subparts %%%%%%%%%%%%%%
%%%%%%%%%%%%%%% Solution by John, K %%%%%%%%%%%%%%
\makeatletter
\newcommand{\subtotal}{\@ifundefined{subtotal@\roman{question}@\roman{partno}}%
{}%
{\csname subtotal@\roman{question}@\roman{partno}\endcsname}}
\new@hlfcntr{part@subtotal}
\let\normal@subparts=\subparts
\let\endnormal@subparts=\endsubparts
\renewenvironment{subparts}% no arguments?
{\set@hlfcntr{part@subtotal}{0}%
\normal@subparts
\let\normal@subpart=\@doitem
\let\@doitem=\my@subpart
}{%
\endnormal@subparts
\ifnum\c@part@subtotal>0
\immediate\write\@auxout{\string\gdef\string\subtotal@\roman{question}@\roman{partno}%
{\prtaux@hlfcntr{part@subtotal}}}%
\fi
}
\newcommand{\my@subpart}[1][\@empty]{%
\ifx\@empty#1\relax
\expandafter\normal@subpart
\else
\ifx\@empty\@details
\else
\addto@hlfcntr{part@subtotal}{#1}%
\fi
\expandafter\normal@subpart\expandafter[\expandafter#1\expandafter]%
\fi
}%
\makeatother
\newcommand{\hidepoints}{\pointformat{}} % Hides my points
\newcommand{\showpoints}{\pointformat{\textbf{\thepoints}}} % Shows my points
\begin{document}
\begin{questions}
%%%%%%%%%%% The problem below %%%%%%%%%%%%%%5
\question
This is my problem
\begin{parts}
\part[\subtotal] I don't want to see the subtotal of 5. % I don't want to see the \subtotal on my paper, but I need it to tell LaTeX as this parts total points is the sum of the subparts below.
\begin{subparts}
\subpart[2] This subpart has 2 points.
\subpart[3] This subpart has 3 points.
\end{subparts}
This is another problem
\part[\subtotal] I don't want to see the subtotal of 2. % I don't want to see the \subtotal on my paper, but I need it to tell LaTeX as this parts total points is the sum of the subparts below.
\begin{subparts}
\subpart[1] This subpart has 1 points.
\subpart[1] This subpart has 1 points.
\end{subparts}
\end{parts}
\droptotalpoints % Another problem as a result is Why the total points for Question 1 = 12 when it should be 7 (5+2)?
%%%%%%%%%% My current work around for the above problem below %%%%%%%%%
\question This is my not so great solution.
\hidepoints % I have hidden by \subtotal result.
\begin{parts}
\part[\subtotal] % I don't want to see the \subtotal on my paper, but I need to tell latex that this part is the sum of the subparts below.
\showpoints % Now i have to show points or else the \subparts won't be dispalyed.
\begin{subparts}
\subpart[2]
\subpart[3]
\end{subparts}
\end{parts}
\end{questions}
\end{document}
*问题
我可以通过在命令之间添加\hidepoints
和来手动显示和隐藏所有子部分的小计,但我注意到,如果一个问题中有 2 个子部分,则该问题的总分计算不正确。\showpoints
\parts[\subtotal]
理想情况下我想提出一个解决方案:
a) 自动隐藏\subtotal
命令。b) 计算问题的正确分数。