![如何定制考试文档类中的多项选择题解决方案?](https://linux22.com/image/290195/%E5%A6%82%E4%BD%95%E5%AE%9A%E5%88%B6%E8%80%83%E8%AF%95%E6%96%87%E6%A1%A3%E7%B1%BB%E4%B8%AD%E7%9A%84%E5%A4%9A%E9%A1%B9%E9%80%89%E6%8B%A9%E9%A2%98%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%EF%BC%9F.png)
\documentclass[cancelspace,10pt]{exam}
\usepackage{multicol}
%********************************************************** End of Listing Setting
\usepackage[explicit]{titlesec}
\usepackage[dotinlabels]{titletoc}
\usepackage{pifont}
\usepackage{times,color}
\usepackage{tikz}
\usepackage{circuitikz}
\usepackage{enumerate}
\usepackage{xepersian}
% *********************************************************** Document Font
\settextfont[Scale=1.2]{B Nazanin}
%*******************************************
\renewcommand*\questionlabel{\color{blue}\thequestion-}
\renewcommand*\thechoice{\arabic{choice}}
\renewcommand*\choicelabel{\thechoice)}
%*******************************answer
\renewcommand{\solutiontitle}{\noindent\textbf{solution:}\par\noindent}
\shadedsolutions
\definecolor{SolutionColor}{rgb}{0.8,0.9,1}
\printanswers
% *********************************************************** begin Doc
%\DefaultMathsDigits
\begin{document}
% ----------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%end-title
\begin{persian}
\begin{questions}
% *********************************************************** Start Doc
\begin{latin}
%#############################################################################
% *********************************************************** Start QUESTION #1
\question
She's not very .............. in the way she treats her children;they may be punished today for somthing they were rewarded for yesterday!
% *********************************************************** Choices
\begin{multicols}{4}
\begin{choices}
%**************************************************************************** Choice 1
\choice
a
%**************************************************************************** Choice 2
\choice
b
%**************************************************************************** Choice 3
\choice
c
%**************************************************************************** Choice 4
\choice
d
\end{choices}
\end{multicols}
\begin{solutionorbox}[2in]
a
\end{solutionorbox}
% *********************************************************** End QUESTION #1
\end{latin}
\end{questions}
\end{persian}
\end{document}
答案1
我认为您可以使用此代码来修改您的代码。
\documentclass{exam}
\usepackage{xcolor}
\usepackage{ifthen}
\shadedsolutions
\definecolor{SolutionColor}{rgb}{0.8,0.9,1}
\printanswers
\newcommand{\answer}{unknown}
\newcommand{\correct}[1]
{
\ifthenelse{\equal{#1}{a}}{\renewcommand{\answer}{The first }}{}
\ifthenelse{\equal{#1}{b}}{\renewcommand{\answer}{The second }}{}
\ifthenelse{\equal{#1}{c}}{\renewcommand{\answer}{The third }}{}
\ifthenelse{\equal{#1}{d}}{\renewcommand{\answer}{The fourth }}{}
\renewcommand{\solutiontitle}{\noindent \textbf{Solution:} \answer option is correct.\par\noindent}
\begin{solutionorbox}[2in]
#1
\end{solutionorbox}
}
\begin{document}
\correct{a}
\correct{b}
\correct{c}
\correct{d}
\end{document}
将显示
编辑
在编辑的
\correct
命令中,您需要输入数字格式中必须包含的格式\correct{option}{the answer}
。option
在您的示例中,选项是1
、2
、3
或4
。\documentclass{exam} \usepackage{xcolor} \usepackage{ifthen} \usepackage{fmtcount} \shadedsolutions \definecolor{SolutionColor}{rgb}{0.8,0.9,1} \printanswers \newcommand{\correct}[2] { \renewcommand{\solutiontitle}{\noindent \textbf{Solution:} The \textcolor{red}{\ordinalstringnum{#1}} option is correct.\par\noindent} \begin{solutionorbox}[2in] \textcolor{red}{#2} \end{solutionorbox} } \begin{document} \correct{1}{c} \correct{2}{d} \correct{1}{You should choose this as your answer} \correct{2}{I think this is the right answer} \end{document}
第二次编辑:
请用这个代码替换
\newcommand{\correct}[2]
上面的代码。\newcommand{\answer}{unknown} \newcommand{\correct}[2] { \ifthenelse{\equal{#1}{1}}{\renewcommand{\answer}{pertama }}{} \ifthenelse{\equal{#1}{2}}{\renewcommand{\answer}{kedua }}{} \ifthenelse{\equal{#1}{3}}{\renewcommand{\answer}{ketiga }}{} \ifthenelse{\equal{#1}{4}}{\renewcommand{\answer}{keempat }}{} \renewcommand{\solutiontitle}{\noindent \textbf{Solution:} The \answer option is correct.\par\noindent} \begin{solutionorbox}[2in] #2 \end{solutionorbox} }
如果您需要使用波斯语,只需将
pertama
、kedua
、ketiga
和替换keempat
为您的语言。
答案2
这是一个可能的解决方案。我定义了一个\CorrectSolution
带有可选参数的命令,该命令将传递给可选参数solutionorbox
:
\CorrectSolution[2in]
以及在环境\coreectoption
内部用来choices
选择正确答案的命令:
\begin{choices}
\correctoption{a}
\choice b
\choice c
\choice d
\end{choices}
然后\CorrectSolution
将借助包自动获取正确答案的值并将其转换为相关的序数字符串fmtcount
。
代码:
\documentclass[cancelspace,10pt]{exam}
\usepackage{multicol}
\usepackage{fmtcount}
\usepackage{color}
\renewcommand*\questionlabel{\color{blue}\thequestion-}
\renewcommand*\thechoice{\arabic{choice}}
\renewcommand*\choicelabel{\thechoice)}
%*******************************answer
\renewcommand{\solutiontitle}{\noindent\textbf{solution:}\par\noindent}
\shadedsolutions
\definecolor{SolutionColor}{rgb}{0.8,0.9,1}
\newcounter{tmp}
\newcommand\correctoption[1]{\gdef\Correctoption{#1}\choice#1\setcounter{tmp}{\value{choice}}}
\newcommand\CorrectSolution[1][-1t]{%
\begin{solutionorbox}[#1]
The \ordinalstring{tmp} option is correct.\par\Correctoption
\end{solutionorbox}%
}
\printanswers
\begin{document}
\begin{questions}
\question
She's not very .............. in the way she treats her children;they may be punished today for somthing they were rewarded for yesterday!
\begin{multicols}{4}
\begin{choices}
\correctoption{a}
\choice b
\choice c
\choice d
\end{choices}
\end{multicols}
\CorrectSolution[2in]
\question
What is the answer to the ultimate question of life, the universe, and everything?\begin{multicols}{4}
\begin{choices}
\choice 15
\choice 23
\choice $\pi$
\correctoption{42}
\choice 31
\end{choices}
\end{multicols}
\CorrectSolution[2in]
\end{questions}
\end{document}
由于我的系统没有该B Nazanin
字体,我注释掉了该行。我还删除了与答案无关的包和设置。