我正在写一些包含多项选择题的笔记,每个问题有 4 个选项,其中 0、1、2、3 或 4 个选项可能是正确的。我正在使用任务包来编写选项。(我没有使用任何类,因为它是一种书,我使用任务包是因为我希望一些选项以水平标签打印在两列中。)
我遇到的问题是我想在其中有一个正确/真实的选择选项,并希望在每个部分末尾显示答案。我无法定义正确/真实的选择选项,也无法在末尾打印它们。我已经看过所有与此相关的问题,但它们没有我想要的。
请帮我
我的代码是
\documentclass{article}
\usepackage{endnotes}
\usepackage{tasks}
\NewTasksEnvironment[style=enumerate, counter-format=($\alph*$),label-width=4ex,item-indent =2em,label-offset=0em]{choices}[\choice](1)
\NewTasks[style=enumerate, counter-format=($\alph*$),label-width=4ex,item-indent =2em,label-offset=0em]{choices2}[\choice](2)
\NewTasks[style=enumerate, counter-format=($\alph*$),label-width=4ex,item-indent =2em,label-offset=0em]{choices4}[\choice](4)
% Define two new counters for ease of using.
\newcounter{questionnumber}
\newcounter{choicenumber}[questionnumber]
% Formatting the counters, this is where you change how the counters
% appear.
\renewcommand*\thequestionnumber{\arabic{questionnumber}.}
\renewcommand*\thechoicenumber{\alph{choicenumber})}
% Define the \question and \choice commands to be similar to what is
% given in the OP
\newcommand*\question{\item}
%\newcommand*\choice{\item}
% Here's a bit of a hack: \endnotetext stores the \meaning of the its argument
% in the endnotetext file, so the macros aren't expanded. I use \edef to fully
% expand the current \thechoicenumber, and use \expandafter to stuff it into
% the argument for \endnotetext. Suggestions for improvements are welcome!
\newcommand*\entreplace[1]{\endnotetext[\value{questionnumber}]{#1}}
\newcommand\truechoice[2]{\item #1 \edef\tempchoice{\thechoicenumber} \expandafter\def\expandafter\currentcount\expandafter{\tempchoice \ \ #2} \expandafter\entreplace\expandafter{\currentcount}}
% Define a choices environment, just a list basically.
%\newenvironment{choices}{\begin{tasks}{\thechoicenumber}{\usecounter{choicenumber}}}{\end{tasks}}
% These are to set up the endnotes. The first makes the endnote marks look
% like the question numbering (as opposed to being in superscript). The second
% sets the endnotes heading to read "Answers".
\renewcommand*\makeenmark{\theenmark.~~}
\renewcommand*\notesname{Answers:}
\begin{document}
\section{Section 1}
\begin{list}{\thequestionnumber}{\usecounter{questionnumber}}
\question Some question
\begin{choices}
\truechoice{True choice}{}
\choice False choice
\choice Bad choice
\choice Bad choice
\end{choices}
\end{list}
% Print the "answers"
\theendnotes
\section{Section 2}
\begin{list}{\thequestionnumber}{\usecounter{questionnumber}}
\question Some question
\begin{choices2}
\choice False choice
\truechoice{True choice}{}
\choice Bad choice
\choice Bad choice
\end{choices2}
\end{list}
% Print the "answers"
\theendnotes
\section{Section 3}
\begin{list}{\thequestionnumber}{\usecounter{questionnumber}}
\question Some question
\begin{choices4}
\choice False choice
\choice Bad choice
\truechoice{True choice}{}
\choice Bad choice
\end{choices4}
\end{list}
% Print the "answers"
\theendnotes
\end{document}
这就是我得到的
答案1
我想这就是你的意思
如果我对多个部分执行此操作,则不会显示不同的答案。有什么想法可以解决这个问题吗?
在对我之前问题的回答的评论中具有正确选择环境的多项选择题”我不明白(因为答案本身就构成了一个部分……)而且你没有费心去启发我。几个月前我就应该修改我的答案了……
以下是该答案的修改版本,采用了相同的建议语法。
只需要稍作修改,即检查定义中对应练习的部分值\getanswers
:
\ifnum\ExercisePropertyGet{##1}{##2}{section-value}=\value{section} ... \fi
下面的代码给出:
\documentclass{article}
\usepackage[no-files]{xsim}
\usepackage{tasks}
\DeclareExerciseEnvironmentTemplate{item}
{\item[\GetExerciseProperty{counter}]}
{}
\DeclareExerciseProperty{answer}
\newcommand*\answer[1]{%
\expanded{%
\SetExerciseProperty{answer}{ (\noexpand\textit{\alph{task}})}}%
#1%
}
\newcommand*\getanswers{%
\section*{Answers}
\def\betweenanswers{\def\betweenanswers{\hspace{2em}}}%
\ForEachUsedExerciseByID{%
\ifnum\ExercisePropertyGet{##1}{##2}{section-value}=\value{section}
\betweenanswers##3\ExercisePropertyGet{##1}{##2}{answer}%
\fi
}%
}
\xsimsetup{
exercise/template = item,
exercise/the-counter = \arabic{exercise}. ,
exercise/within = section
}
\NewTasksEnvironment[
label = (\textit{\alph*}) ,
label-width = 14pt
]{choice}[\choice]
\newenvironment{questions}
{\itemize}
{\enditemize}
\begin{document}
\section{Problems}
\begin{questions}
\begin{exercise}
What is the product of $-2$ and $3$?
\begin{choice}(4)
\choice \answer{$-6$}
\choice $6$
\choice $5$
\choice $-5$
\end{choice}
\end{exercise}
\begin{exercise}
What is the sum of $-2$ and $-3$?
\begin{choice}(4)
\choice $-6$
\choice $6$
\choice $5$
\choice \answer{$-5$}
\end{choice}
\end{exercise}
\end{questions}
\getanswers
\section{Other Problems}
\begin{questions}
\begin{exercise}
What is the sum of the sides of a polygon called?
\begin{choice}(2)
\choice Leg
\choice \answer{Perimeter}
\choice Area
\choice Volume
\end{choice}
\end{exercise}
\end{questions}
\getanswers
\end{document}