用文本框替换 \vspace

用文本框替换 \vspace

我有一个enumerate列表,其中的项目以 分隔\vspace {1 in}

每个\item问题都需要在该空间内回答,我想创建一个“可能的答案表”,在其中输入一些问题的可能答案。我希望答案表保持与原始文件相同的页面布局和页码,因此我需要将答案放入高度为 1 英寸的“框”中。我还需要这些框来允许我更改字体大小、颜色,还允许我使用数学模式。

\item This is question 1.

\vspace{1 in}
%I need to replace this with the "answer box"

 \item This is question 2. So how much is $2+2$

\vspace{1 in}
%I need this box to allow me to type $2+2=4$

*continues on*

答案1

这是同类事物的另一个版本。您可以添加一些装饰,但这就是它了。

\documentclass{article}
\usepackage{xcolor}

\makeatletter

\newcounter{ae@problem@cnt}
\newcommand\problem{\stepcounter{ae@problem@cnt}\textbf{\arabic{ae@problem@cnt})}\hspace*{0.5em}}

\newsavebox\ae@question@box
\newsavebox\ae@answer@box
\newif\if@showanswer@
%% a command to format the boxes for question and answer
%% #1=control sequence for box                          
%% #2=width of box                                      
%% #3=content of box                                    
\long\def\ae@save@mp#1#2#3{%%
  \begin{lrbox}{#1}
    \begin{minipage}[t]{#2}
      #3
    \end{minipage}
  \end{lrbox}}

%% a command to trigger when aswers will appear
\newcommand\showanswers{\@showanswer@true}
%% Using two boxes is probably overkill
%% only one for the answer would suffice.
%% #1=height of answer space
%% #2=content of question
%% #3=content of answer
\newcommand\question[3][1in]{%%
  \ae@save@mp\ae@question@box{\textwidth}{\problem #2}%%
  \ae@save@mp\ae@answer@box{\dimexpr\textwidth-2em}{\color{red}#3}%%  
  \noindent
  \usebox\ae@question@box
  \newline
  \begin{minipage}[c][#1]{\textwidth}
    \vspace{-\dimexpr\ht\strutbox-\lineskip}
    \if@showanswer@
      \centering
      %%
      \usebox{\ae@answer@box}%%
      \par
    \fi
  \end{minipage}%%
}

\makeatother

\begin{document}

\showanswers
\question[1in]
         {sdlfkj lsdfjk sliewoi m sdfie lkjsdlfkjeio u}
         {this is my answer}

\question[1in]
          {Find the area bounded by the $x$-axis and the curve $y=x^{2}-4$}
          {To find the area evaluate the following integral:
           \[
              \int_{-2}^{2} x^{2}-4\,\mathrm{d}x
           \]
           }

\end{document}

\showanswers存在 时的结果:在此处输入图片描述

\showanswers不存在时:

在此处输入图片描述

答案2

添加一个盒子。;-)

\documentclass{article}

\newcommand{\questionbox}[2][1in]{%
  \item #2\\*
  \begingroup
  \setlength{\fboxsep}{-\fboxrule}%
  \fbox{\rule{0pt}{#1}\rule{\linewidth}{0pt}}%
  \endgroup
  \par
}

\begin{document}

\begin{enumerate}

\questionbox{This is a question}

\questionbox[2in]{This is a more difficult question}

\questionbox{This is a question}

\questionbox{This is a question}

\questionbox{This is a question}

\questionbox{This is a question}

\questionbox{This is a question}

\questionbox{This is a question}

\questionbox{This is a question}

\end{enumerate}

\end{document}

在此处输入图片描述

您可以为问题指定注释的变体,这些注释仅在\shownotestrue处于活动状态时显示。

\documentclass{article}

\newif\ifshownotes
\newsavebox{\questionboxbox}
\newenvironment{questionbox}[2][1in]
 {\def\questionboxheight{#1}%
  \item #2\\*
  \begin{lrbox}{\questionboxbox}
  \begin{minipage}[t][#1]{\dimexpr\linewidth-2\fboxsep-2\fboxrule}}
 {\end{minipage}%
  \end{lrbox}%
  \ifshownotes
    \fbox{\usebox\questionboxbox}%
  \else
    \fbox{%
      \parbox[t][\questionboxheight]{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{
        \strut\hspace*{\fill}
      }%
    }%
  \fi}

\begin{document}

\begin{enumerate}

\begin{questionbox}{This is a question}
Some notes about this question
\end{questionbox}

\begin{questionbox}{This is a more difficult question}
Some notes about this question
Some notes about this question
Some notes about this question
Some notes about this question
Some notes about this question
Some notes about this question
Some notes about this question
Some notes about this question
\end{questionbox}

\begin{questionbox}[.5in]{This is an easy question}
Some notes about this question
\end{questionbox}

\end{enumerate}

\clearpage

\shownotestrue

\begin{enumerate}

\begin{questionbox}{This is a question}
Some notes about this question
\end{questionbox}

\begin{questionbox}{This is a more difficult question}
Some notes about this question
Some notes about this question
Some notes about this question
Some notes about this question
Some notes about this question
Some notes about this question
Some notes about this question
Some notes about this question
\end{questionbox}

\begin{questionbox}[.5in]{This is an easy question}
Some notes about this question
\end{questionbox}

\end{enumerate}

\end{document}

在此处输入图片描述

相关内容