13

How does one define a single page to be \raggedbottom? Or, for completion's sake, \flushbottom?

Background

In a comment to a related answer, Ben Lerner provided the following snippet of code to declare a single page to be \raggedbottom:

\def\oneraggedpage{\raggedbottom\afterpage{\flushbottom}}

When I tried this, it did not work as expected: instead of making a single page \raggedbottom it made the entire document. Besides, even if this is made to work) this way of doing things assumes that the default state (into which the document needs to return after the page is shipped out) is \flushbottom, which may or may not be the case (cf. \ensuremath).

So the question is, what is the best way to scope the effects of \raggedbottom (or some such) to a single page?

(Apologies for no MWE, but it's difficult to come up with one in this case)

Sample case

If it helps to think about how this could be useful, think of writing a paper in which the references go in an additional page at the end. By default, the last page can be ragged even without \raggedbottom. But if the last page will have the references, the "final page" of the document itself would be the page before the references.

Maybe in this case (the actual case that motivated me) the changes can be integrated into the bibliography's environment?

4
  • 1
    Can't \clearpage just be used to create a single ragged-bottomed page? Feb 5, 2015 at 21:08
  • @StevenB.Segletes \clearpage requires knowing the exact break point. Feb 6, 2015 at 9:11
  • @Andrew. Yes, but if one wants just one page ragged, one is doing it with an "intention in mind". Given the intentionality of the whole thing, one can intentionally place the \clearpage with equal effectiveness, in just about all cases of which I can think. Feb 6, 2015 at 11:00
  • Hmm, yeah, I see the point. But it's easier if you don't need to know the exact place where the page should end, as long as you know that you are in the right page. Still, that's a good point.
    – jja
    Feb 6, 2015 at 23:47

2 Answers 2

9

\afterpage groups its argument, and as \flushbuttom doesn't set its values globally they are lost. You need a "global" variant of \flushbottom:

\documentclass{article}

\usepackage{afterpage}
\usepackage{lipsum}
\begin{document}
\flushbottom
\lipsum[1-2]
\pagebreak
\raggedbottom\lipsum[1-2]
\makeatletter
\afterpage{\global\let\@textbottom\relax \global\let\@texttop\relax}
\pagebreak\lipsum[1-2]
\pagebreak abc


\end{document}
2
  • Nice! And Andrew's answer takes care of reading the current state. However, since that was really more of a cherry-on-top kind of problem, I'll accept this as the answer.
    – jja
    Feb 5, 2015 at 23:29
  • Excellent - of course it is the scoping issue... Feb 6, 2015 at 7:44
5

Updated \global added before \let in \afterpage as explained in Ulrike Fischer's answer. Without that the code below does not work as intended - \raggedbottom is applied to two consecutive pages not one. Thanks to StevenB.Segletes for pointing this out.

Here is a version capturing the current setting, assuming the bottom alignment is achieved purely by adjusting \@textbottom and \@texttop. This is true in standard LaTeX, and in the memoir class. It does not quite capture memoirs \sloppybottom though.

\documentclass{article}

\usepackage{afterpage}
\usepackage{lipsum}

\makeatletter
\newcommand{\oneraggedpage}{\let\mytextbottom\@textbottom
  \let\mytexttop\@texttop
  \raggedbottom
  \afterpage{%
  \global\let\@textbottom\mytextbottom
  \global\let\@texttop\mytexttop}}

\begin{document}
\flushbottom
%\raggedbottom
\lipsum[1-6]

\vspace{1ex plus 30ex}
\vrule height 10cm
\vspace{1ex plus 30ex}

\oneraggedpage
\lipsum[7]

\vspace{1ex plus 30ex}
\vrule height 10cm
\vspace{1ex plus 30ex}

\lipsum[8-20]

\end{document}
4
  • What am I missing? When I compile, it appears pages 2 AND 3 are ragged. Feb 5, 2015 at 17:45
  • @StevenB.Segletes Your are perfectly right - looking at the result of \showoutput page 3 is ragged too and then we get flush after that. I'll leave this here for the moment as example of code that doesn't work - but isn't as drastically wrong as the poster was expecting. Feb 5, 2015 at 20:43
  • I didn't know how \raggedbottom and \flushbottom worked. :) However, as informative as it is, there is that problem Steven Segletes pointed out.
    – jja
    Feb 5, 2015 at 23:24
  • Combining this with Ulrike's \global\lets it works as expected. :)
    – jja
    Feb 5, 2015 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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