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.

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}
share|improve this question
    
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
add comment

2 Answers

up vote 13 down vote accepted

Make your rule into a discardable item:

\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.

share|improve this answer
    
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
  \leaders\vrule width \textwidth\vskip0.4pt
  \nointerlineskip\vskip5pt
}
%\raggedbottom
\begin{document}
\absdiscnt0
\loop
  \advance\absdiscnt by 1\relax
  \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}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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