Adding some text on a page break

How can one test if certain chunks of text (say, numbered questions in a questionnaire) is split between two pages and add automatically related text ("Continued question NN") on the top of the second page?

(That is what longtable does with its head, but I need it for plain text.)

I doubt if MWE make sense here, 'cause I'm not reporting a bug and I cannot suggest any solution to the problem. Anyway, let it be.

\documentclass{book}

\usepackage{geometry}
\geometry{lines=9,showframe}

\def\lorem{Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.}

\newcounter{question}
\newcommand\question[1]{\par
\refstepcounter{question}\textbf{\thequestion.} #1\par}

\begin{document}
\question{\lorem}
\question{\lorem}
\question{\lorem}

\end{document}


I would like to have a line Continued question 2 as a 1st line of page 2 body for 9-lines body and nothing for 10-lines body. As longtable does with its ...\endhead instruction.

I think about 2 solutions: one just puts the chunk in a vbox, tests if its height is greater than the remaining space and, if necessary, vsplits it and adds page break followed by the desired text and the remainigs (iterating if it is too big for one page).

Another one puts 2 labels at the beginning and the end of a chunk and defines a command for page N (the command name includes N as its part) that prints the desired line if these two label appears on pages N-1 and N. This command can be called from \output, but I don't know the right way and moment to do it.

• 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 Oct 20 '13 at 17:22
• I added MWE in my question although I doubt if it makes sense here – Vadim Radionov Oct 20 '13 at 21:01

I'm not sure in your specific case as you didn't paste a WME, but I would have a serious look to the extramarks package. The doc is here : http://www.ntg.nl/maps/16/29.pdf (p.13) and you'll find a sample just like this one :

\usepackage{extramarks}
...
\pagestyle{fancy}