Is there a way to find out, whether the currently typeset material will go to top of a page?

I am trying to write a macro which, when invoked, typesets a horizontal divider to separate the subsequent content from the preceding one. However, if the subsequent content goes to top of the next page, the horizontal divider should be suppressed. How could I do that?

I am aware \pagetotal and \thepage are not the way to go (the page-breaking algorithm often decides where to put the break when the material is already typeset and my macro has been invoked).


TeX provides a very useful but relatively little employed way to typeset horizontal rules depending on whether or not they happen to be the last element in the textblock on the page. That's to incorporate your rule within vertical glue (recall that TeX ordinarily ignores final vertical glues in textblocks). Calling on one of the \leaders family of commands should get you where you want. E.g., using \cleaders, you can write:


  \cleaders\vbox to 0.4pt{\hrule width\linewidth}\vskip0.4pt%

  I am trying to write a macro which, when invoked, typesets a
  horizontal divider to separate the subsequent content from
  the preceding one.\par\divider}

That's all!
  • 2
    Could you explain what your code is doing? It looks like the vbox nudges things up, and then the vskip nudges them back again. This seems like the net effect should be nil. But it isn't, so there's something I haven't understood. (I think it would be nice if answers did more than just solve the problem, but also taught people about TeX and friends... – Seamus Dec 3 '10 at 13:43
  • 2
    The \cleaders takes a box and a space argument, and places as many copies of the box it needs to fill the space. It can be used both in vertical and horizontal mode. Here the box is a vertical box with a height of 0.4pt, and the space is also a vertical space of 0.4pt so the box will be used once to fill the space. So there is no nudging back and forth. The point is that the box with the rule is within vertical glue, and does not have the status as a text box, so it will be ignored at the end of the page. – Jørgen Tesman Mar 15 '11 at 13:50
  • @Jørgen: You can't comment at a different question or answer until you get 50rep points. This is in force to prevent harm by spam-bots etc. I converted it to a comment for you. – Martin Scharrer Mar 15 '11 at 13:59
  • @Martin: how's he supposed to get rep if you go and convert his answers to comments, huh? :-P – SamB Mar 31 '11 at 20:11
  • @SamB: His "answer" started with "This is really a comment to the comment to Geoffrey Jones' answer, but I couldn't figure out how to do that, so it's posted as an answer.", so I didn't had much hesitation to convert it. – Martin Scharrer Mar 31 '11 at 20:14

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.