4

How can I define a macro that does nothing if it is the first item on a page, but does something (e.g. inserts a rule or a space) if it appears elsewhere?

Something along these lines is discussed in section 28.4.5 of TeX by Topic, but I don't understand it well enough to customise it.

Ian Thompson
  • 43,767

1 Answers1

4

Glue disappears at the top of the page; glue is a special case of leaders, that have the same property:

\newcommand{\disappearing}{\par % we need to be in vertical mode
  \cleaders\vbox to 24pt{\hrule\vfill\hbox{SOMETHING}\vfill\hrule}%
  \vskip24pt}

\newpage
\disappearing

some text

\disappearing

The box will appear only after "some text", not at the top of the page.

egreg
  • 1,121,712