问题中包含答案的问题

问题中包含答案的问题

我想要创建一些问题,每个问题都包含一系列填空内容。

我想显示一个工作表,其中答案行代替答案。然后是一个工作表,其中答案包含在答案行上。最后在末尾显示所有答案。

我的目标是:

填空题工作表。 问题

填有空白的问题工作表 包含问题和答案

仅提供答案

在此处输入图片描述

我看过一些诸如锻炼和考试之类的套餐,但我认为我无法完全操纵它们来获得我想要的东西......

答案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}

以下是代码生成的结果\showAns 带有空格的问题

\showAns 问题与答案

tocloft 包生成了\listofanswer

仅提供答案

相关内容