0

I would like to be able to test whether a paragraph has one or more page breaks. If it does, I would like to print text immediately after each break. In some cases a paragraph may not have a break; in other cases there may be one or more breaks. I understand this would probably require wrapping in an environment or macro.

Answers to similar questions have suggested using counters to compare page numbers. This allows me to determine whether there is a break, but is not useful for inserting text after that break (and I can't see it working if there were multiple breaks).

Including an example is difficult because it's just a paragraph of text, but here's an attempt:

\testifbreak{Cras mattis consectetur purus sit amet fermentum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec sed odio dui. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus.}

What I would like this to do is test if that chunk of text extends over a page. If it does not, it would just print the text as-is. If it did extend over the page I would like it to print something like:

Cras mattis consectetur purus sit amet fermentum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec sed odio dui. Maecenas


CONTINUED

sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus.

On each subsequent page, I would like it to print 'CONTINUED' if the text goes over the page.

Help is greatly appreciated!

EDIT

I edited the above question on the suggestion of @DavidCarlisle, who indicated it was unclear (and on reflection I agree that it was).

@TeXnician provided an example using tcolorbox in their answer which worked perfectly. Many thanks for that!

  • Welcome to TeX.SX! You could use an empty tcolorbox. – TeXnician Jul 17 '17 at 9:01
  • probably \afterpage does what you want. (from the package of that name) – David Carlisle Jul 17 '17 at 11:32
  • @DavidCarlisle How would one insert that at the point where the break is? In this context not all paragraphs reach over the page. I need to test for a break and then insert, immediately after that break, some text. \afterpage prints the inserted text on the page after the paragraph, but I need it at the top of the same page. – experimenthouse Jul 17 '17 at 13:34
  • @TeXnician Thank you! Could you give me an example of how that would work? – experimenthouse Jul 17 '17 at 13:34
  • It is very hard to understand your question as you have not provided any usable example code, but your question seems to imply CONTINUED appears at the top of the page following the page break which is what \afterpage{CONTINUED ... the inserted text .... } would do. – David Carlisle Jul 17 '17 at 14:11
1

Here's a solution using tcolorbox. That only works if you're willing to use an environment.

continue

\documentclass{article}

\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins}
\newtcolorbox{mybreak}{
    enhanced jigsaw,breakable,frame hidden,interior hidden,boxrule=0pt,boxsep=0pt,left=0pt,right=0pt,top=0pt,bottom=0pt,
    title after break={\color{black}CONTINUED\vspace*{\baselineskip}}
}

\usepackage{lipsum}

\begin{document}
\begin{mybreak}
\lipsum\lipsum\lipsum
\end{mybreak}
\end{document}
  • This works perfectly! It means wrapping every paragraph in an environment (or inside a macro if there are other formatting conditions to be applied), as you say, but that's a small price to pay. Thank you! – experimenthouse Jul 18 '17 at 7:53
  • @experimenthouse What do you mean with other formatting conditions? The most formattings can be applied within the environment. – TeXnician Jul 18 '17 at 8:02
  • I meant that if the text was being formatted specially anyway, your solution could be integrated easily. For example: \myparagraph[1]{\begin{center}\begin{mybreak}#1\end{mybreak}\end{center}}. – experimenthouse Jul 18 '17 at 8:12
  • @experimenthouse You can use the center environment within the box. If you wanted, you could even wrap your whole document in it (okay, without floating figures and tables). – TeXnician Jul 18 '17 at 8:14
  • @experimenthouse But formatting is of course up to you. If the answer solved your problem consider upvoting and/or accepting it. – TeXnician Jul 18 '17 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.