# Making a text box replace a \vspace

I have an enumerate list that has it's items separated by a \vspace {1 in}.

Each \item is a question that needs to be answered within that space, and, I want to create a "possible answers sheet", where I type in some possible answers for the questions. I would like the answer sheet to keep the same page layout and page number as the original file so I need my answers to fit inside a " box" with 1 inch height. I will also need those boxes to allow me to change font size, color and also allow me to use math mode.

\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*

• There are a number of packages (exam.cls for example) which do this sort of thing. Personally, I don't use them (see elfsoft2000.com/worksheets/index.htm). – John Kormylo Mar 12 '16 at 14:35
• I was hoping to do it without those exam-like packages, actually. – Guilherme Vargas Mar 12 '16 at 14:36
• using the vspace mid document is misusing the list really. The whole point of list structures is that you specify in advance teh vertical and horizontal space requirements. If you used a list with \itemsep being set to 1in items would be separated by 1in no need for vspace on every item. – David Carlisle Mar 12 '16 at 16:38
• @DavidCarlisle I just used 1in as an example, on my usual files I have different spacings for different items. Thank you for the alert, though! – Guilherme Vargas Mar 12 '16 at 17:13

Here's another iteration of the same sort of thing. You could add some frills, but here it goes.

\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
%% 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
%% Using two boxes is probably overkill
%% only one for the answer would suffice.
%% #2=content of question
\newcommand\question[3][1in]{%%
\ae@save@mp\ae@question@box{\textwidth}{\problem #2}%%
\noindent
\usebox\ae@question@box
\newline
\begin{minipage}[c][#1]{\textwidth}
\vspace{-\dimexpr\ht\strutbox-\lineskip}
\centering
%%
\par
\fi
\end{minipage}%%
}

\makeatother

\begin{document}

\question[1in]
{sdlfkj lsdfjk sliewoi m sdfie lkjsdlfkjeio u}

\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}


Result when \showanswers is present:

and when \showanswers is not present:

• Just so I know: Using your method is it possible to add items like...1) find the area bounded by the x-axis and the curves: (a) y=x (b) y = x^2 (c) y = x^3...? – Guilherme Vargas Mar 16 '16 at 2:36
• @GuilhermeVargas Is that a math question or a LaTeX question? If it's a LaTeX quesiton, you can write whatever you want in the given parts to the question and answer. – A.Ellett Mar 16 '16 at 4:13
• It's a LaTeX question. I was wondering if "Question 2" in your example could have sub items (a), (b) and so on.. – Guilherme Vargas Mar 16 '16 at 13:14
• @GuilhermeVargas Sure you could. You'll have to tweak things a bit: namely, separate out the question and answer parts of my answer. I don't have time to update my answer right now, but I'll try to get to it later today. – A.Ellett Mar 16 '16 at 14:46
• Alright, @A.Ellett! I will wait for your help once again, I am typing a document that could use that solution :) – Guilherme Vargas Mar 16 '16 at 22:25

Add a box. ;-)

\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}


A variant where you can specify notes to the question, which are shown only if \shownotestrue is active.

\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}
\end{questionbox}

\begin{questionbox}{This is a more difficult question}
\end{questionbox}

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

\end{enumerate}

\clearpage

\shownotestrue

\begin{enumerate}

\begin{questionbox}{This is a question}
\end{questionbox}

\begin{questionbox}{This is a more difficult question}
\end{questionbox}

\begin{questionbox}[.5in]{This is an easy question}