Is something the first item on a page?

How can i identify logically, whether something is the first item on a page, i.e. there is nothing above it (apart from header)?

Consider the following, is is basically a feature environment, which puts a rule above some content, to separate it from anything prior.

Acceptable Output:

\documentclass{article}
\usepackage{lipsum}

\newenvironment{feature}[1]{
\vspace*{\baselineskip}
\hrule
\vspace*{\baselineskip}
\textbf{#1}\\
}{
\vspace*{\baselineskip}
}

\begin{document}

%THIS CASE SHOULD HAVE RULE
\lipsum[1]
\begin{feature}{This is the title}
\lipsum[1]
\end{feature}

\end{document}


However...

If the environment is the only item on a page, or at the top of the page, the rule is not only superfluous, but actually, completely undesirable. How can I switch the rule on / off depending on whether there is content directly above.

Undesirable Output:

\begin{document}
%THIS CASE SHOULD NOT
\newpage
\begin{feature}{This is the title}
\lipsum[1]
\end{feature}
\end{document}


-

Leaders help because they vanish at the top of the page, e.g.:

\documentclass{article}
\usepackage{lipsum}

\newenvironment{feature}[1]{%
\par
\vss
\hrule width\linewidth
\vss
}\vskip2\baselineskip
\textbf{#1}\\
}{
\vspace*{\baselineskip}
}

\begin{document}

%THIS CASE SHOULD HAVE RULE
\lipsum[1]
\begin{feature}{This is the title}
\lipsum[1]
\end{feature}

\newpage
\begin{feature}{Title 2}
\lipsum[1]
\end{feature}

\end{document}


Remarks:

• Leaders (\leaders, \cleaders, \xleaders) vanish at the top of a new page in the same way as \vbox{...}. Usually they are used in the table of contents for the dotted lines.
• (Box) leaders have the syntax: Leader command followed by a box specification and a glue specification. The box is put as often as needed to fill the specified glue space. In this case, we want to set the box once exactly, thus the height of the box is the same as the specified space (2\baselineskip).
• If the boxes does not fill the space entirely, then \cleaders puts the boxes in the middle and the additional space on the outside. \xleaders divides the space by the number of boxes that are needed and centers each box in the calculated space. (This does not apply here, because there is only one box that fills the space exactly, thus there is no additional space to distribute.)
• Further reading about leaders: "TeX by Topic, Section 9.2 Leaders" by Victor Eijkhout.
• \par is added to end a previous paragraph.
• \vbox to 2\baselineskip{...} is similar to LaTeX's \parbox[b][2\baselineskip]{\linewidth}{...}, but more efficient and can be used after \cleaders.
• The pair of \vss vertically centers the rule inside the box. It is similar to LaTeX's \vspace{0pt plus 1fill minus 1fill}.
• \hrule width\linewidth is the plain TeX form for \hrule{\linewidth}{.4pt}, because the default for the height of \hrule is 0.4pt.
• \vskip2\baselineskip is the plain version of LaTeX's \vspace{2\baselineskip}.
-
Thankyou!!!..... –  Nicholas Hamilton May 18 '13 at 1:06
Will this work if it is a sole item on a page, and vertically centered? –  Nicholas Hamilton May 18 '13 at 1:07
The horizontal line is vertically centered in the space of two \baselineskip if this is used to separate items. –  Heiko Oberdiek May 18 '13 at 1:10
No I mean the whole environment, similar to a float with [p] option. –  Nicholas Hamilton May 18 '13 at 1:47
@ADP: I have tried to add some remarks/explanations, but without knowing, what is unclear, it is quite difficult without copying chapters from "The TeXbook". –  Heiko Oberdiek Jun 23 '13 at 10:46