Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
prevent “action” if top of page

I have some blocks of text, separated by a \hline. Because the LaTeX code is generated automatically from user-entered data, sometimes the \hline appears last on the page, and sometimes it appears first.

Since the \hline is only used to provide a clear division between blocks, it's not needed last or first on the page, since the page break itself provides the division. Is it possible to hide/ignore/delete the \hline if it would be the first or last element on the page?

Here is some example code to illustrate the issue:

\vspace{20cm} % Adjust as necessary
\parbox[t]{3cm}{Example:}\parbox[t]{15cm}{This is an example}
\hline
\parbox[t]{3cm}{Example:}\parbox[t]{15cm}{This is an example}
\hline
\parbox[t]{3cm}{Example:}\parbox[t]{15cm}{This is an example}
share|improve this question
add comment

marked as duplicate by egreg, diabonas, Marco Daniel, Claudio Fiandrino, doncherry Sep 19 '12 at 18:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 9 down vote accepted

Using \leaders you can define a rule that will "disappear" at the beginning of a page:

\documentclass{article}
\usepackage[paperheight=7cm,textwidth=18cm]{geometry}% just for the example

\newcommand\Myrule{%
  \par\leaders\vrule width \textwidth\vskip0.4pt\par\nobreak
}

\begin{document}
\vspace*{3.64cm} % Adjust as necessary

\noindent\parbox[t]{3cm}{Example:}\parbox[t]{15cm}{This is an example}
\Myrule
\noindent\parbox[t]{3cm}{Example:}\parbox[t]{15cm}{This is an example}
\Myrule
\noindent\parbox[t]{3cm}{Example:}\parbox[t]{15cm}{This is an example}
\Myrule
\noindent\parbox[t]{3cm}{Example:}\parbox[t]{15cm}{This is an example}

\end{document}

enter image description here

share|improve this answer
add comment

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