練習包中的多項選擇題

練習包中的多項選擇題

我正在為學生創建一個作業,其中包含一些帶有理論、練習和解決方案的章節。我想使用乳膠練習包創建多項選擇題。我相信這個包不直接支援 MCQ。我遇到了一些我組合的程式碼。

我的目標是創建包含一個或多個正確答案的 MCQ,以便所有答案以及解釋和分析都應出現在本章末尾。

如果有人建議其他包/方法,那也很好。

\documentclass[a4paper]{amsbook}
\usepackage[margin=1in]{geometry}
\usepackage{mathptmx}
\usepackage[cmintegrals, cmbraces]{newtxmath}
\usepackage{hyperref}% you must load it before the exercise package
\usepackage[answerdelayed]{exercise}
\usepackage{environ}

\newlength{\choiceslen}
\newif\ifshowcorrect
\newcounter{choices}
\newcommand{\choicefinal}[1]{%
\ifnum\value{choices}>0 \hfill\fi\egroup
\hspace{0pt}%
\hbox to\choiceslen
\bgroup
\stepcounter{choices}%
\ifcase#1\relax
(\Alph{choices})%
\else
\ifshowcorrect
\expandafter\bfseries
\fi
{(\Alph{choices})}%
\fi\space
}
\newcommand{\choicetemp}[1]{%
\stepcounter{choices}%
\space(\Alph{choices})\cr
}

\NewEnviron{choices}{%
\setcounter{choices}{0}%
\let\choice\choicetemp
\shorthandchoice% <---------- Add \choice shorthand
\settowidth{\choiceslen}{\vbox{\halign{##\hfil\cr\BODY\crcr}}}
\ifdim\choiceslen>.5\textwidth
\setlength{\choiceslen}{\textwidth}%
\else
\ifdim\choiceslen>.25\textwidth
\setlength{\choiceslen}{.5\textwidth}%
\else
\setlength{\choiceslen}{.25\textwidth}%
\fi
\fi
\let\choice\choicefinal
\shorthandchoice% <---------- Add \choice shorthand
\setcounter{choices}{0}%

\begin{flushleft}
\bgroup\BODY\hfill\egroup
\end{flushleft}
}

\newcommand{\shorthandchoice}{%
\let\oldchoice\choice
\renewcommand{\choice}{\oldchoice{0}}
\def\correctchoice{\oldchoice{1}}
}
\parindent 0pt
\linespread{1.1}

\begin{document}
\begin{Exercise}[label={mylabel}]
What is the value of 2+5? Which fruit do you like?(To see the answer click here: \refAnswer{\ExerciseLabel})
\showcorrecttrue
\begin{choices}
\correctchoice apple
\choice banana
\correctchoice orange
\choice pear
\end{choices}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
7 
\end{Answer}

\begin{ExerciseList}
\Exercise What is the value of $\pi$  \showcorrecttrue
\begin{choices}
\correctchoice apple
\choice banana
\correctchoice orange
\choice pear
\end{choices}
\Answer Approximate value is 22/7.
\Exercise What is the value of $e$
\Answer Approximate value is 2.71...
\end{ExerciseList}
\clearpage
\begin{center}
\textbf{\textit{    Answers.}}
\end{center}
\newpage % I've added a new page only to clearly show the hyperlink. Of course, you don't need it in your document.
\shipoutAnswer
\end{document}

答案1

我不確定這是否是您想要實現的目標,但您可以使用taskspackage.json 。

答案的更新版本

由於 (2019/10/04) 版本 v1.0tasks該選項counter-format已被棄用,現在可以label像在enumitem.

\documentclass[a4paper]{amsbook}
\usepackage[margin=1in]{geometry}
\usepackage{mathptmx}
\usepackage[cmintegrals, cmbraces]{newtxmath}
\usepackage{hyperref}% you must load it before the exercise package
\usepackage[answerdelayed, lastexercise]{exercise}
\usepackage{tasks}
\settasks{
    label = {(\Alph*)},
    label-width=1.4em
    }

\begin{document}
\chapter{Exercises}
\begin{Exercise}[label={mylabel}]
What is the value of 2+5? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task 2
\task 5
\task\label{correctchoice}7
\task 3
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{correctchoice} 7
\end{Answer}
\begin{Exercise}[label={mysecondlabel}]
Which fruit do you like? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task\label{apple}apple
\task banana
\task\label{orange}orange
\task pear
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{apple} apple or \ref{orange} orange 
\end{Answer}
\begin{Exercise}[label={mythirdlabel}]
What is the value of $\pi$? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task 2.15
\task 1.31
\task 4.3
\task\label{correct}3.14
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{correct} 3.14
\end{Answer}
\chapter{Answers}
\shipoutAnswer
\end{document}

舊版的答案

\documentclass[a4paper]{amsbook}
\usepackage[margin=1in]{geometry}
\usepackage{mathptmx}
\usepackage[cmintegrals, cmbraces]{newtxmath}
\usepackage{hyperref}% you must load it before the exercise package
\usepackage[answerdelayed, lastexercise]{exercise}
\usepackage{tasks}
\settasks{
    counter-format = {(tsk[A])},
    label-width=1.4em
    }

\begin{document}
\chapter{Exercises}
\begin{Exercise}[label={mylabel}]
What is the value of 2+5? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task 2
\task 5
\task\label{correctchoice}7
\task 3
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{correctchoice} 7
\end{Answer}
\begin{Exercise}[label={mysecondlabel}]
Which fruit do you like? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task\label{apple}apple
\task banana
\task\label{orange}orange
\task pear
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{apple} apple or \ref{orange} orange 
\end{Answer}
\begin{Exercise}[label={mythirdlabel}]
What is the value of $\pi$? (To see the answer click here: \refAnswer{\ExerciseLabel})
\begin{tasks}(4)
\task 2.15
\task 1.31
\task 4.3
\task\label{correct}3.14
\end{tasks}
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
\ref{correct} 3.14
\end{Answer}
\chapter{Answers}
\shipoutAnswer
\end{document}

在這兩種情況下,輸出都是:

在此輸入影像描述

在此輸入影像描述

相關內容