2

I use the exam class to typeset my exams. I usually leave space for answers with \fillwithlines{3in} because I prefer to fix the amount of space. However, when a question is at the end of a page and the space required by \fillwithlines{3in} exceeds it, the lines do not continue on the next page. Instead, the entire question is moved to the next page while the current page is blank space. Is there a way to change that behavior and have lines starting on one page and then continue on the next.

\documentclass{exam}
\begin{document}
\begin{questions}
\question This question should appear on page 1. It should be followed by lines which continue on page 2.
\fillwithlines{20in}
\end{questions}
\end{document}

1 Answer 1

2

Just had to replace \cleaders with a loop. The \space allows line breaks.

\documentclass{exam}
%\usepackage{showframe}% mwe only

\makeatletter
\def\fillwithlines#1{%
  \begingroup
  \ifhmode
    \par
  \fi
  \hrule height \z@
  \nobreak
  \setbox0=\hbox to \hsize{\hskip \@totalleftmargin
          \vrule height \linefillheight depth \z@ width \z@
          \linefill}%
  % We use \cleaders (rather than \leaders) so that a given
  % vertical space will always produce the same number of lines
  % no matter where on the page it happens to start:
  \dimen0=\ht0
  \loop\ifdim\dimen0<#1\relax
    \advance\dimen0 by \ht0
    \copy0\space
  \repeat
  \endgroup
}
\makeatother

\begin{document}
\begin{questions}
\question This question should appear on page 1. It should be followed by lines which continue on page 2.
\fillwithlines{20in}
\end{questions}
\end{document}
3
  • Works great! Is there a clean way to change this for all \fillwith commands at once?
    – marco
    Feb 7, 2017 at 13:01
  • The etools package has tools to edit source code without having to see the source code, but it still only does one macro at a time. (Personally, I find editing code without being able to see the final product rather frightening.) Feb 7, 2017 at 15:39
  • I went through some of the \fillwith macros and I guess they have to be done one at a time since the edit changes slightly.
    – marco
    Feb 7, 2017 at 16:52

You must log in to answer this question.

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