# prevent “action” if top of page

I have a manual list of stuff that are sometimes separated by an hrule(or my own custom ruler) for visual purposes.

Sometimes the hrule ends at the top or bottom of a page which makes it useless.

Is there a way to prevent it from being added if it is at the top or bottom of a page?

MWE of problem:

\documentclass{book}
\usepackage{tikz}
\begin{document}
\newcommand\rulesep{%
\par % make sure we end a paragraph
\vskip5pt % space above the rule
\leaders\vrule width \textwidth\vskip0.4pt % rule thickness is 0.4pt
\nointerlineskip % disable interline glue here
\vskip5pt % space below the rule
}
\def\dotikzcircle#1{\begin{tikzpicture}\draw(0,0)circle(#1);\end{tikzpicture}}
\rulesep
\noindent This is a test\noindent
\rulesep
\noindent End of test
\rulesep
\dotikzcircle3
\rulesep
\begin{center}\dotikzcircle3\end{center}
\rulesep
\begin{center}\dotikzcircle3\end{center}
\rulesep
\dotikzcircle1
\rulesep
\dotikzcircle2
\rulesep
\dotikzcircle3
\rulesep
\dotikzcircle4
\rulesep
\dotikzcircle5
\rulesep
\end{document}

-
Just remove the last \rulesep command: there's no way to remove glue if there is no following page. –  egreg Jun 29 '12 at 13:33

\newcommand\disappearingrule{%
\par % make sure we end a paragraph
\vskip5pt % space above the rule
\leaders\vrule width \textwidth\vskip0.4pt % rule thickness is 0.4pt
\nointerlineskip % disable interline glue here
\vskip5pt % space below the rule
}


Because of the page breaking rules of TeX, no break can be taken at the vertical leaders or at the following \medskip. If a page break is taken at the \bigskip, the following glue (or leaders) will disappear.

-
Thanks. Can you explain how to adjust the thickness and what \leaders does? Also, I want the same space to be on both sides. You seem to hard code the lower half space. My current rule is \newcommand\rulesep{\par\kern 5pt\hrule height 1pt\kern 5pt\par} which has 5pt's on both sides. Yours is not usable by me unless both top and bottom space is the same. –  AbstractDissonance Jun 29 '12 at 7:42
@AbstractDissonance I've changed the implementation. Modify at will the parameters. However a 1pt thick rule is really too thick. –  egreg Jun 29 '12 at 8:43
Yours is still not symmetric for me. I've added an MWE. My original hrule is symmetric expect between centered and non-centered environments as centering seems to add some extra vertical space for some reason. I center all my graphics so this is not an issue since all get the same extra space. With your rule, while it does solve the original problem seems to still have more space above it than below which I can hard code to get an approximately symmetric rule but would like something like my original code. –  AbstractDissonance Jun 29 '12 at 9:56
note that I replace the vkips with kern and it seems to work in my original code except I end up with the rules at the top and bottom. (this suggests it may be a more difficult problem) i.e., vskip gives the correct behavior but not symmetric and kern gives the wrong behavior but symmetric. –  AbstractDissonance Jun 29 '12 at 9:58
@AbstractDissonance The problem is that book uses flushbottom, so the "asymmetry" you see is due to the \parskip that's enlarged to fill the page. Use \raggedbottom in that context. –  egreg Jun 29 '12 at 10:05
show 1 more comment

Here is an extended demonstration of egreg’s solution.

\documentclass{book}
\usepackage{tikz}
\usepackage{pgfpages}
\pgfpagesuselayout{8 on 1}[a4paper,landscape,border shrink=2.5mm]
\newcount\absdiscnt
\newcommand\rulesep{%
\par\vskip5pt
\nointerlineskip\vskip5pt
}
%\raggedbottom
\begin{document}
\absdiscnt0
\loop
\ifnum\absdiscnt<121\relax
\rulesep
\centerline{Eh, this line is by Abstract Dissonance!}\endgraf
\rulesep
\edef\tempa{\the\dimexpr.25\baselineskip}
\edef\tempb{\the\dimexpr\textwidth-2\tempa-\parindent}
\begin{tikzpicture}
\draw[fill=blue](0,0)circle(\tempa);
\draw[fill=red](\tempb,0)circle(\tempa);
\end{tikzpicture}
\repeat
\end{document}


-