考虑:
\documentclass{article}
\usepackage{comment}
% \includecomment{answer} %show answers
\excludecomment{answer} % do not show answers
\begin{document}
Question 1: How many hours are in a day?
\begin{answer}
There are 24 hours in a day.
\end{answer}
Question 2: How many minutes are in an hour?
\begin{answer}
There are 60 minutes in an hour.
\end{answer}
\end{document}
取决于以下两条线中的哪一条:
\includecomment{answer} %show answers
\excludecomment{answer} % do not show answers
是文档的一部分并且被注释掉,答案行将显示或不显示。
如果处于活动状态,是否可以\excludecomment{answer}
保留问题行之间的间距?间距量应为问题行之间的间距是否包括答案。截至目前,当答案被排除时,问题之间没有间距。
这个想法是创建在问题之间留有空格的文档,以便学生可以在课堂上用笔/铅笔填写空格,而我保留排版的答案。
如果comment
包装无法实现这一点,那么任何其他保留间距的替代方法也是有用的。
答案1
快速而粗略(假设您不想在文档中使用花哨的颜色)。
\documentclass{article}
\usepackage{xcolor,graphicx}
\newcommand{\answer}{\color{white}}
\newcommand{\question}{\color{black}}
\begin{document}
\question
Question 1: How many hours are in a day?
\answer
There are 24 hours in a day.
\question
Question 2: How many minutes are in an hour?
\answer
There are 60 minutes in an hour.
\end{document}
答案2
这将使用 lrbox 和 minipage 创建一个新的答案环境。
\documentclass{article}
\usepackage{showframe}% alignment tool
\newif\ifshowanswers
\newsavebox{\answerbox}
\newenvironment{answer}{\par%\noindent
\begin{lrbox}{\answerbox}%
\begin{minipage}[t]{\dimexpr \linewidth-\parindent}}% body
{\end{minipage}\end{lrbox}%
\ifshowanswers
\usebox\answerbox\par
\else
\vskip\ht\answerbox
\vskip\dp\answerbox
\fi}
\showanswerstrue
%\showanswersfalse
\begin{document}
Question 1: How many hours are in a day?
\begin{answer}
There are 24 hours in a day.
\end{answer}
Question 2: How many minutes are in an hour?
\begin{answer}
There are 60 minutes in an hour.
\end{answer}
\end{document}