[Tex/LaTex] Repeating a block of text until it fills a page

loopsmacrosvertical alignment

Might I please have some help with writing a loop that repeats a block of text as many times as there is remaining space for it on the page?

I would like to produce an notebook in TeX which is divided into a number of sections. Each section would start with some printed records (taken from an existing database) followed by some space to hand-write in new entries.

The space for handwritten records is generated by something along the following lines:

\noindent Type of Widget: \dotfill \break
Observations: \dotfill \break
\null\dotfill

The problem I have is that of vertical alignment: I want each section to start at the top of a new page, followed by the printed records and then enough blocks for handwritten notes to fill up the remaining vertical space on that page. Something like this:


Section: Special Widgets

Type of Widget: ABC123

Observations: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse id orci nunc, sed sollicitudin lectus.

Type of Widget: CDE123

Observations: Etiam lacus sem, pharetra vel eleifend ac, elementum at leo. Ut pulvinar, lorem sit amet feugiat hendrerit, sapien justo accumsan eros, eleifend consectetur nisl urna at nibh.

Type of Widget: ………..

Observations: ………………………………………………………………………………………

…………………………………………………………………………………………………………….

Type of Widget: ………..

Observations: ………………………………………………………………………………………

…………………………………………………………………………………………………………….


Since the length of the records can vary, I therefore need to run a loop which does something like the following (in eplain pseudo code):

\for
    \noindent Type of Widget: \dotfill \break
    Observations: \dotfill \break
    \null\dotfill
\if **test to see if there is enough vspace to repeat block**
\repeat

Could anyone point me in the right direction as to how to write a test for "is there enough space left on the page to print this block of text?". I presume I would start by making a \vbox the size of the block and then see if it will fit onto the current page but I can't work out how to make that work.

I hope this is clear enough. If not, please let me know.

Thanks.

-Jacob

Best Answer

This is a place to use vertical leaders. Here is a starting point.

\documentclass{article}
\usepackage{lipsum}
\newsavebox\widgetbox
\begin{document}
\setbox\widgetbox\vbox
  {\vspace*{6pt}\noindent Type of Widget: \dotfill \break
  Observations: \dotfill \break
  \null\dotfill\par}

\lipsum[1]

\cleaders\copy\widgetbox\vskip0pt plus 1fill
\end{document}

With \cleaders the boxes will be put right on top of each other, with space added on top and bottom to fill the page. Use \xleaders instead to have the extra space between the boxes.

You could also use \leaders, which should place these boxes in the same position on every page. But then you need to pay attention to dimensions. Ideally, the page height should be a whole multiple of the height of your \widgetbox.