[Tex/LaTex] How to write in a box with fixed height

box

I am using report class and have been using \framebox[\linewidth]{\rule{0pt}{2cm}} to create an empty box with a certain height. Now, I would like to write in that empty box. By referring to How can I write something in a box with \makeemptybox{1.8in}?, I achieved the following:

\documentclass[a4paper,11pt]{report}

\newcommand{\makenonemptybox}[2]{%
\par\nobreak\vspace{\ht\strutbox}\noindent
\fbox{%
\parbox[c][\dimexpr#1-2\fboxsep][t]{\dimexpr\linewidth-2\fboxsep}{
  \hrule width \hsize height 0pt
  #2
 }%
}%
\par\vspace{\ht\strutbox}
}
\makeatother

\begin{document}
\begin{enumerate}
\item Tell me about yourself.
    \begin{enumerate}
    \item What is your name?
    \makenonemptybox{2cm}{My name is Nadia.}
    \item Where are you from?
    \makenonemptybox{2cm}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam a venenatis lacus. Nunc vitae mollis neque. Maecenas vel arcu erat.}
    \item How old are you?
    \item[] \framebox[\linewidth]{\rule{0pt}{2cm}}
    \end{enumerate}
\end{enumerate}

\end{document}

As you can see \makenoemptybox makes a bigger vertical space compared to \framebox (refer to the coloured arrows). How can I make the vertical space made by \makenoemptybox follows that of \framebox?

enter image description here

Best Answer

Use in the definition of \makenonemptybox the same method you use for \framebox to close current paragraph. Of course, that will restrict its usage to list environments.

\documentclass[a4paper,11pt]{report}

\newcommand{\makenonemptybox}[2]{%
%\par\nobreak\vspace{\ht\strutbox}\noindent
\item[]
\fbox{% added -2\fboxrule to specified width to avoid overfull hboxes
% and removed the -2\fboxsep from height specification (image not updated)
% because in MWE 2cm is should be height of contents excluding sep and frame
\parbox[c][#1][t]{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{
  \hrule width \hsize height 0pt
  #2
 }%
}%
\par\vspace{\ht\strutbox}
}
\makeatother

\begin{document}
\begin{enumerate}
\item Tell me about yourself.
    \begin{enumerate}
    \item What is your name?
          \makenonemptybox{2cm}{My name is Nadia.}
    \item Where are you from?
          \makenonemptybox{2cm}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam a venenatis lacus. Nunc vitae mollis neque. Maecenas vel arcu erat.}
    \item How old are you?
    \item[] \framebox[\linewidth]{\rule{0pt}{2cm}}
    \end{enumerate}
\end{enumerate}

\end{document}

enter image description here

Related Question