答案1
我想出了一个可以满足我需求的解决方案。这可能对其他人有帮助。如果有人有其他建议,我将不胜感激,因为我只是在瞎折腾。
\documentclass[12pt,a4paper]{article}
\usepackage{ifthen}
\usepackage{tocloft}
\usepackage{exercise}
\usepackage{tasks}
% Set the Show Answers Boolean
\newboolean{showAns}
\setboolean{showAns}{false}
\newcommand{\showAns}{\setboolean{showAns}{true}}
% The length of the Answer line
\newlength{\answerlength}
\newcommand{\anslen}[1]{\settowidth{\answerlength}{#1}}
% ans command that indicates space for an answer or shows the answer in red
\newcommand{\ans}[1]{\settowidth{\answerlength}{\hspace{2ex}#1\hspace{2ex}}%
\ifthenelse{\boolean{showAns}}%
{\textcolor{red}{\underline{\hspace{2ex}#1\hspace{2ex}}}}%
{\underline{\hspace{\answerlength}}}}%
% Formatting how multiple choices Questions are formated.
\settasks{counter-format={tsk[A].}}
% Some commands for the Exercise Question package
\renewcommand{\QuestionNB}{\Large\protect\textcircled{\small\bfseries\arabic{Question}}\ }
\renewcommand{\ExerciseHeader}{} %no header
\renewcommand{\QuestionBefore}{3ex} %Space above each Q
\setlength{\QuestionIndent}{8pt} % Indent after Q number
% To create the list of answers with tocloft...
\newcommand{\listanswername}{Answers}
\newlistof[Question]{answer}{Answers}{\listanswername}
% Creates a TOC for Answers
\newcounter{prevQ}
\newcommand{\answer}[1]{\refstepcounter{answer}%
\ans{#1}%
\ifnum\theQuestion=\theprevQ%
\addcontentsline{Answers}{answer}{\protect\numberline{}#1}% don't include the Q number
\else%
\addcontentsline{Answers}{answer}{\protect\numberline{\theQuestion}#1}%
\setcounter{prevQ}{\value{Question}}%
\fi%
}%
%tocloft formatting listofanswers
\renewcommand{\cftAnswerstitlefont}{\bfseries\large}
\renewcommand{\cftanswerdotsep}{\cftnodots}
\cftpagenumbersoff{answer}
\addtolength{\cftanswernumwidth}{10pt}
\begin{document}
\showAns
\begin{Exercise}
\Question $1+2$ is (\answer{C})
\begin{tasks}(4)
\task 1
\task 2
\task 3
\task 4
\end{tasks}
\Question $2+3=$~\answer{$5$}
\Question A question might have multiple places for the answer. The first answer is \answer{This is the answer}. The second answer is \answer{this is the other answer}.
\end{Exercise}
%Now just the answers
\listofanswer
\end{document}
tocloft 包生成了\listofanswer