我正在尝试修改从西科拉这样,我就可以添加\question
并subparts
指向成绩表。
到目前为止我已经修改了代码。
我的MWE
\documentclass[addpoints]{exam}
\usepackage{xparse,booktabs,xpatch}
% redefine \part command to be \mypart
\appto\parts{\let\exampart\part\let\part\mypart}
\appto\subparts{\let\examsubpart\part\let\part\mysubpart} %subpart
\appto\question{\let\examquestion\part\let\part\myquestion} %question
\makeatletter
\ExplSyntaxOn
\tl_new:N \g_grade_table_tl% this will; become the new grade table
\int_new:N \g_score_int% this will be the exam score
\NewDocumentCommand\mypart{o}{
\IfNoValueTF{#1}{\exampart}{
% don't do anything special inside solutions
\if@insolution\exampart[#1]
\else\exampart[#1]
\int_compare:nNnT {\arabic{partno}} = {1} {
\tl_gput_right:Nn \g_grade_table_tl { \midrule }
}
\tl_gput_right:Nx \g_grade_table_tl {
\arabic{question}\alph{partno}
}
\tl_gput_right:No \g_grade_table_tl {& #1 & \\}
\int_gadd:Nn \g_score_int {#1}
\fi
}
}
% Subpart
\NewDocumentCommand\mysubpart{o}{
\IfNoValueTF{#1}{\examsubpart}{
% don't do anything special inside solutions
\if@insolution\examsubpart[#1]
\else\exampart[#1]
\int_compare:nNnT {\arabic{subpartno}} = {1} {
\tl_gput_right:Nn \g_grade_table_tl { \midrule }
}
\tl_gput_right:Nx \g_grade_table_tl {
\arabic{question}\alph{subpartno}
}
\tl_gput_right:No \g_grade_table_tl {& #1 & \\}
\int_gadd:Nn \g_score_int {#1}
\fi
}
}
% question
\NewDocumentCommand\myquestion{o}{
\IfNoValueTF{#1}{\examquestion}{
% don't do anything special inside solutions
\if@insolution\examquestion[#1]
\else\examquestion[#1]
\int_compare:nNnT {\arabic{questionno}} = {1} {
\tl_gput_right:Nn \g_grade_table_tl { \midrule }
}
\tl_gput_right:Nx \g_grade_table_tl {
\arabic{question}\alph{questionno}
}
\tl_gput_right:No \g_grade_table_tl {& #1 & \\}
\int_gadd:Nn \g_score_int {#1}
\fi
}
}
\NewDocumentCommand\GradeTable{}{% the new grade table
\begin{tabular}{ccc}\toprule Question & Points & Score \\
\tl_use:N \g_grade_table_tl \midrule
Total & \int_use:N \g_score_int & \\\bottomrule
\end{tabular}
}
\ExplSyntaxOff
\makeatother
\begin{document}
\begin{questions}
\question[2] This is question 1
\question What if there were no air?
\begin{parts}
\part[4]
Describe the effect on the balloon industry.
\part[6]
Describe the effect on the aircraft industry.
\end{parts}
\question
\begin{parts}
\part[12]
Define the universe.
Give three examples.
\part[8]
If the universe were to end, how would you know?
\part
\begin{subparts}
\subpart[10] Subpart 1
\subpart[5] Subpart 2
\end{subparts}
\end{parts}
\end{questions}
\GradeTable
\end{document}
我想要的是:
编辑
我设法从另一个编辑代码问题。
我的 MWE:
\documentclass[addpoints]{exam}
\usepackage[table]{xcolor}
\usepackage{xparse,xpatch,etoolbox}
% redefine \question command to be \myquest
\appto\questions{\let\examquestion\question\let\question\myquestion}
% redefine \part command to be \mypart
\appto\parts{\let\exampart\part\let\part\mypart}
% redefine \part command to be \mysubpart
\appto\subparts{\let\examsubpart\subparts\let\subparts\mysubpart}
\def\multiplechoice{10}
\def\freeresponse{0}
\makeatletter
\ExplSyntaxOn
% this will become a sequence of the part numbers and scores
% like: 1a,10,1b,8,1c,9,2a,6,2b,8,3,12,4,14, ...
\clist_new:N \g_grades_clist
\clist_new:N \g_grades_aux_clist
\int_new:N \g_row_int
\int_new:N \g_multiple_choice_int
\int_new:N \g_free_response_int
\int_new:N \g_grade_total_int
\int_new:N \g_number_of_scores_int
% add a question/part number and score to \g_grades_clist
\cs_new:Nn \__add_to_grades_list:nn {
\clist_gput_right:Nx \g_grades_clist { #1 }
\clist_gput_right:Nx \g_grades_clist { #2 }
}
\NewDocumentCommand\myquestion{o}{
\IfNoValueTF{#1}{\examquestion}{
% don't do anything special inside solutions
\if@insolution\examquestion[#1]
\else\examquestion[#1]
% store both the part number and score in \g_grades_clist
\__add_to_grades_list:nn { \arabic{question} } { #1 }
\fi
}
}
\NewDocumentCommand\mypart{o}{
\IfNoValueTF{#1}{\exampart}{
% don't do anything special inside solutions
\if@insolution\exampnrt[#1]
\else\exampart[#1]
% store both the part number and score in \g_grades_clist
\__add_to_grades_list:nn { \arabic{question}\alph{partno} } { #1 }
\fi
}
}
\NewDocumentCommand\mysubpart{o}{
\IfNoValueTF{#1}{\examsubpart}{
% don't do anything special inside solutions
\if@insolution\examsubpart[#1]
\else\examsubpart[#1]
% store both the part number and score in \g_grades_clist
\__add_to_grades_list:nn { \arabic{question}\alph{partno}\roman{mysubpart} } { #1 }
\fi
}
}
\AtEndDocument{
\iow_now:cx { @auxout } {
\token_to_str:N \SetGradeList { \g_grades_clist } ^^J
\token_to_str:N \SetMultipleChoice {\multiplechoice} ^^J
\token_to_str:N \SetFreeResponse {\freeresponse} ^^J
}
}
% set grade list, multiple choice and free responses from the aux file
\NewDocumentCommand\SetGradeList{m}{\clist_gset:Nn \g_grades_aux_clist {#1}}
\NewDocumentCommand\SetMultipleChoice{m}{\int_gset:Nn \g_multiple_choice_int {#1}}
\NewDocumentCommand\SetFreeResponse{m}{\int_gset:Nn \g_free_response_int {#1}}
% print row #1 of the part scores in the grade table
\cs_new:Nn \__add_row_to_grade_table: {
\int_gincr:N \g_row_int
\clist_item:Nn \g_grades_aux_clist {2*\g_row_int-1}
&\clist_item:Nn \g_grades_aux_clist {2*\g_row_int}
\int_gadd:Nn \g_grade_total_int {\clist_item:Nn \g_grades_aux_clist {2*\g_row_int}}
&&
\int_compare:nTF {2*\g_row_int+\g_number_of_scores_int <= \clist_count:N \g_grades_aux_clist }{
\clist_item:Nn \g_grades_aux_clist {2*\g_row_int+\g_number_of_scores_int-1}
&\clist_item:Nn \g_grades_aux_clist {2*\g_row_int+\g_number_of_scores_int}
\int_gadd:Nn \g_grade_total_int {\clist_item:Nn \g_grades_aux_clist {2*\g_row_int+\g_number_of_scores_int}}
}{&}
&\\\hline
\int_compare:nT {\g_row_int < \g_number_of_scores_int/2} { \__add_row_to_grade_table: }
}
\NewDocumentCommand\PrintGradeTable{}{% the new grade table
% we need an exam number of scores so add two
% empty cells if we have an odd number
\int_set:Nn \g_number_of_scores_int {(\clist_count:N \g_grades_aux_clist)/2}
\int_if_odd:nT {\g_number_of_scores_int} {
\int_add:Nn \g_number_of_scores_int {1}
}
\int_gzero:N \g_row_int % a counter to step through the rows
\int_add:Nn \g_grade_total_int { \g_multiple_choice_int }
\int_add:Nn \g_grade_total_int { \g_free_response_int }
% create the grade table
\begin{tabular}{|c|c|c|c|c|c|}\hline\rowcolor{gray!20}
Question & Points~Possible & Points~Earned & Question & Points~Possible & Points~Earned \\\hline
% the number of rows that we need is \g_number_of_scores_int/2
\int_compare:nT {\g_number_of_scores_int>0} { \__add_row_to_grade_table: }
\multicolumn2{c|}{}&\multicolumn{2}{r|}{Multiple~Choice}
& \int_use:N \g_multiple_choice_int & \\\cline{3-6}
\multicolumn2{c|}{}&\multicolumn{2}{r|}{Free~response}
& \int_use:N \g_free_response_int & \\\cline{3-6}
\multicolumn2{c|}{}&\multicolumn{2}{r|}{\textit{Exam~total}}
& \int_use:N \g_grade_total_int & \\\cline{3-6}
\end{tabular}
}
\ExplSyntaxOff
\makeatother
\begin{document}
\PrintGradeTable
\begin{questions}
\question[2] Question 1
\question
\begin{parts}
\part[4]
\part[6]
\end{parts}
\question
\begin{parts}
\part[12]
\part[8]
\end{parts}
\question
\begin{parts}
\part
\begin{subparts}
\subpart[10]
\subpart[5]
\end{subparts}
\end{parts}
\end{questions}
\end{document}