假设我正在使用考试类。有一个选项\printanswers
可以打印解决方案,否则不会打印解决方案。我想隐藏问题并只打印解决方案。这可能吗?
编辑
我已经添加了一个基本的解决方法,但也许有更好的方法可以做到这一点?这是一个使用修改后的考试类的演示,找到这里。
% Document
\documentclass[12pt]{exam2}
\usepackage[margin=1.0in]{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath}
\pagestyle{fancy}
\lhead{The author}
\rhead{The assignment}
\setcounter{section}{1}
\unframedsolutions
% Preamble
\printquestions
\printanswers
\begin{document}
\numberwithin{question}{section}
\begin{questions}
\begin{quest}
What is $\int_{0}^{5} x^2 dx$?
\end{quest}
\begin{solution}
This integral can be calculated as
\begin{align}
\int_{0}^{5} x^3 &= \Big[ \frac{x^3}{3} \Big|_{0}^{5} \notag \\
&= \frac{5^{3}}{3}
\end{align}
\end{solution}
\begin{quest}
The next question would go here
\questp{a}{Part a of the question}
\questsp{i}{Subpart of a}
\questspnob{More information}
\end{quest}
\begin{solution}
The next answer would go here
\begin{parts}
\part Parts works in solution environment
\begin{subparts}
\subpart Here is a subpart
\end{subparts}
\end{parts}
\end{solution}
\end{questions}
\end{document}
问题与解答
% Preamble:
\printquestions
\printanswers
仅限提问
% Preamble:
\printquestions
%\printanswers
仅提供答案
% Preamble:
%\printquestions
\printanswers
答案1
我对 exam.cls 做了以下更改。
首先我添加了一个 \printquestions 选项。
\newif\ifprintanswers
\printanswersfalse
\DeclareOption{answers}{\printanswerstrue}
\DeclareOption{noanswers}{\printanswersfalse}
% BEGIN EDIT %
\newif\ifprintquestions
\printquestionsfalse
\DeclareOption{yesquestions}{\printquestionstrue}
\DeclareOption{noquestions}{\printquestionsfalse}
% END EDIT %
然后后来
\def\printanswers{\printanswerstrue}
\def\noprintanswers{\printanswersfalse}
\def\printquestions{\printquestionstrue}
接下来,我修改解决方案环境。如果我不打印问题,那么我希望解决方案环境充当 \question。
\newenvironment{solution}[1][0pt]{%
\ifprintquestions % act as a solution
\@insolutiontrue % cancelled by the end of the environment
\@addpointsfalse % cancelled by the end of the environment
\ifprintanswers
\begingroup
\Solution@Emphasis
\begin{TheSolution}%
\else
\ifcancelspace
% Do nothing
\else
\par
\penalty 0
\vspace*{#1}%
\fi
\setbox\z@\vbox\bgroup
\fi
\else %act as a question
\question
\fi
}{%
\ifprintquestions %act as a solution
\ifprintanswers
\end{TheSolution}%
\endgroup
\else
\egroup
\fi
\fi
}%
接下来,我添加了一个可以隐藏的任务环境。不过,这需要用来代替 \question。
\newenvironment{quest}[1][0pt]%
{%
\ifprintquestions % act as a question
\question
\else % don't show the question
%\par
%\vspace*{-9mm} %
\setbox\z@\vbox\bgroup
\fi
}{%
\ifprintquestions
% don't do anything
\else % hide the group
\egroup
\fi
}%
一个烦人的事情是,在我定义的环境中,itemize 列表、部分和子部分无法工作(我相信这是由于 \question 调用初始化了一些我没有初始化的变量。因此,我使用表格环境创建了一些基本的 itemize 列表命令。
% PART
\newcommand{\questp}[2]{%
\begin{tabular}{R{0.25cm} p{14.75cm}}
(#1) & #2 \\
\end{tabular}
{}
}
\usepackage{array,booktabs,ragged2e}
\newcolumntype{R}[1]{>{\RaggedLeft\arraybackslash}p{#1}}
\newcommand{\questsp}[2]{%
\hspace*{2em}\begin{tabular}{R{1cm} p{13.15cm}}
(#1) & #2 \\
\end{tabular}
{}
}
% SUBPART
\newcommand{\questssp}[1]{%
\hspace*{8em}\begin{tabular}{p{10.75cm}}
#1 \\
\end{tabular}
{}
}
更多部分命令可以像这样定义。
\newcommand{\questpnob}[1]{%
\begin{tabular}{R{0.25cm} p{13.15cm}}
& #1 \\
\end{tabular}
{}
}
\newcommand{\questspnob}[1]{%
\hspace*{2em}\begin{tabular}{R{1cm} p{13.15cm}}
& #1 \\
\end{tabular}
{}
}