11

I'm creating a document where I want to leave white space of varying heights, e.g. for handwritten answers to questions.

It doesn't matter whether this empty space is bordered or not.

The key thing is that it needs to break across pages, so if I asked for a space of height 6in, but there was only 3in left on the page, I would get 3in on the first page and 3in on the next.

For instance I saw someone use this code here

\def\boxpar[#1]#2#3{{\setlength{\fboxsep}{-\fboxrule}\fbox{\parbox[][#2][t]{#1}{\mbox{}\\[-.125\baselineskip]\mbox{}~#3}}}}

\boxpar[\hsize]{6in}{}

which will create a bordered box 6in tall and the width of the page as required, but if there is not enough space on the first page it will move the whole thing to the next page.

1
  • Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – jub0bs
    May 1, 2013 at 8:20

3 Answers 3

9

Just produce paragraphs, that don't disappear. In order to specify any dimension, just make many of them.

\documentclass{article}
\usepackage{lipsum}

\newcommand{\answerspace}[2][n]{%
  \par\smallskip
  \begingroup
  \if#1r\hrule\fi
  \baselineskip=\dimexpr#2/100\relax
  \lineskip=0pt \parindent=0pt
  \count255=0
  \loop\ifnum\count255<100
    \advance\count255 by 1
    \leavevmode\vbox to\baselineskip{}
    \if#1r\vrule\hfill\vrule\fi\endgraf
  \repeat
  \if#1r\hrule\fi
  \smallskip
  \endgroup
}

\begin{document}
\lipsum[1]

\answerspace[r]{2in}

\lipsum[2]

\answerspace{6in}

\lipsum[3]
\end{document}

With \answerspace[r]{<length>} rules are made.

enter image description here

3
  • Exactly what I was looking for and I appreciate the option to rule or not.
    – James
    May 1, 2013 at 11:28
  • @ egreg what's the main purpose of \smallskip in this example
    – lyl
    Mar 15, 2019 at 7:13
  • @lyl The rules would be too near the text.
    – egreg
    Mar 15, 2019 at 7:18
7

Let try to answer the question using the package mdframed. (Github-version: https://github.com/marcodaniel/mdframed -- newer)

The provided command \boxpar has the following syntax:

\boxpar[<number of lines>]{Text}[<width of the box>]

You can the the number and the width are optional.

mdframed cant split across pages using a simple\vspace`. Therefor the loop is needed.

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\newcounter{tempcount}
\NewDocumentCommand \boxpar {  O{3} m O{\linewidth} }{%
 \begin{mdframed}[align=center,innertopmargin=.4cm,userdefinedwidth=#3]
     \setcounter{tempcount}{0}
     \loop\ifnum\value{tempcount}<#1
        \rule{0pt}{\baselineskip}\\[2pt]      
       \stepcounter{tempcount}
     \repeat
     \ifx\relax#2\relax\else#2\fi
  \end{mdframed}%
}
\begin{document}
\lipsum[1]

\boxpar{}

\lipsum[2]

\boxpar[10]{}[8cm]


\boxpar[6]{3 Points}[8cm]
\end{document}

enter image description here

If you want to modify the style of the frame you can do this by options of mdframed

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\mdfdefinestyle{boxpar}{linewidth=2pt,backgroundcolor=gray!10,roundcorner=10pt,}
\usepackage{lipsum}

\newcounter{tempcount}
\NewDocumentCommand \boxpar {  O{3} m O{\linewidth} }{%
 \begin{mdframed}[align=center,innertopmargin=.4cm,userdefinedwidth=#3,style=boxpar]
     \setcounter{tempcount}{0}
     \loop\ifnum\value{tempcount}<#1
        \rule{0pt}{\baselineskip}\\[2pt]      
       \stepcounter{tempcount}
     \repeat
     \ifx\relax#2\relax\else#2\fi
  \end{mdframed}%
}
\begin{document}
\lipsum[1]

\boxpar{}

\lipsum[2]

\boxpar[10]{}[8cm]


\boxpar[6]{3 Points}[8cm]
\end{document}

If you want horizontal lines you can use:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\mdfdefinestyle{boxpar}{linewidth=2pt,backgroundcolor=gray!10,roundcorner=10pt,}
\usepackage{lipsum}

\newcounter{tempcount}
\NewDocumentCommand \boxpar {  O{3} m O{\linewidth} }{%
 \begin{mdframed}[align=center,innertopmargin=.4cm,userdefinedwidth=#3,style=boxpar]
     \setcounter{tempcount}{1}
     \loop\ifnum\value{tempcount}<\numexpr#1+1\relax
 %       \rule{0pt}{\baselineskip}\\[2pt]      
       \the\value{tempcount}\rule{\linewidth}{.8pt}\\[2pt]
       \stepcounter{tempcount}
     \repeat
     \ifx\relax#2\relax\else#2\fi
  \end{mdframed}%
}
\begin{document}
\lipsum[1]

\boxpar{}

\lipsum[2]

\boxpar[10]{}[8cm]


\boxpar[6]{3 Points}[8cm]
\end{document}

enter image description here


You can also add a title:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\mdfdefinestyle{boxpar}{linewidth=2pt,backgroundcolor=gray!10,roundcorner=10pt,frametitle=Room for your answer,frametitlerule=true}
\usepackage{lipsum}

\newcounter{tempcount}
\NewDocumentCommand \boxpar {  O{3} m O{\linewidth} }{%
 \begin{mdframed}[align=center,innertopmargin=.4cm,userdefinedwidth=#3,style=boxpar]
    \setcounter{tempcount}{0}
     \loop\ifnum\value{tempcount}<#1
        \rule{0pt}{\baselineskip}\\[2pt]      
       \stepcounter{tempcount}
     \repeat
     \ifx\relax#2\relax\else#2\fi
  \end{mdframed}%
}
\begin{document}
\lipsum[1]

\boxpar{}

\lipsum[2]

\boxpar[5]{}[8cm]


\boxpar[6]{3 Points}[8cm]
\end{document}

enter image description here

2
  • Thanks for this answer as well, tried using mdframed earlier but struggled with it, so this is a helpful example for future reference!
    – James
    May 1, 2013 at 11:25
  • @James: If you have any trouble you can contact the author ;-) -- me ;-) May 1, 2013 at 11:32
6

enter image description here

Remove the \vrule\strut\hfill\vrule If you don't want the lines either side.

\documentclass{article}

\def\blanklines#1{%
\ifnum#1>0
\par\noindent\mbox{}\vrule\strut\hfill\vrule\par%
\expandafter\blanklines\expandafter{%
  \the\numexpr#1-1\expandafter\relax\expandafter}%
\fi
}

\begin{document}

stuff

more stuff\par more stuff\par more stuff\par more stuff\par more stuff\par


\blanklines{16}

more stuff\par more stuff\par more stuff\par more stuff\par more stuff\par

\blanklines{25}

more stuff\par more stuff\par more stuff\par more stuff\par more stuff\par

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .