# How can I fill vertical spaces with dotted horizontal lines?

I'm sure this must be a duplicate, but I can't find it.

I'm preparing a worksheet for students to use when starting to work on an assignment. Here is a (naturally sweetened) version of the code:

\documentclass{article}
\usepackage{kantlipsum}
\begin{document}
\begin{flushleft}
Toffee or caramel? \dotfill\medskip

Fudge fantasy fiction: \dotfill\medskip

Curious confectionery connections: \dotfill\medskip\par\mbox{}\dotfill\bigskip
\end{flushleft}

\kant[1]\bigskip

\begin{flushleft}
What do you like best about your preferred confection?\vfill

What are the health implications?\vfill

Does your preferred confection taste really good or just good?
If the latter, how might it be improved?\vfill

\end{flushleft}
\end{document}


This produces:

I would like to replace the spaces created by the \vfill commands with dotted, horizontal lines. Is it possible to do this neatly/nicely and automatically?

I'm aware that packages for exams and tests offer something like this facility in some cases, but I cannot use a specialised exam class in this case because this is just one page in a packet of materials.

There's also little problem filling whole pages this way e.g. to create lined or squared paper of various kinds.

This answer addresses a similar question but I am not sure how to modify it, and I don't want to have to hard code the text width.

I can do this with TikZ if necessary, but I was hoping there might be an easier way.

Here is the code stolen from exam class and modified slightly.

\documentclass{article}
\usepackage{kantlipsum}

\makeatletter
\newlength\dottedlinefillheight
\setlength\dottedlinefillheight{.25in}

\def\fillwithdottedlines{%
\begingroup
\ifhmode
\par
\fi
\hrule height \z@
\nobreak
\setbox0=\hbox to \hsize{\hskip \@totalleftmargin
\vrule height \dottedlinefillheight depth \z@ width \z@
\dotfill}%
\cleaders \copy0 \vfill \hbox{}%
\endgroup
}
\makeatother

\begin{document}

\begin{flushleft}
Toffee or caramel? \dotfill\medskip

Fudge fantasy fiction: \dotfill\medskip

Curious confectionery connections: \dotfill\medskip\par\mbox{}\dotfill\bigskip
\end{flushleft}

\kant[1]\bigskip

\begin{flushleft}
What do you like best about your preferred confection?\fillwithdottedlines

What are the health implications?\fillwithdottedlines

Does your preferred confection taste really good or just good?
If the latter, how might it be improved?\fillwithdottedlines

\end{flushleft}
\end{document}


• This is great! I don't suppose you could add a couple of brief comments to explain what the code does, could you? I'm mostly puzzled by the \hrule height \z@. I think I understand the rest, even though I wouldn't have been able to write it. – cfr Apr 29 '15 at 15:45
• @cfr That \hrule is the reference point from where the horizontal dotted lines will be filled. For example put \hrule height 1pt you will see that line. Without that \hrule code line the spacing between the dotted lines and text and any two dotted lines wouldn't be same. I am sleepy now and this may be the worst explantion I could give ;-) – user11232 Apr 29 '15 at 15:57
• I want to get 5 lines. How can I use \fillwithdottedlines{5\dottedlinefillheight}? – minhthien_2016 Jul 27 '17 at 7:38