9

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}

1 Answers1

10

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

Gonzalo Medina
  • 505,128