1

I am taking inspiration from this post to set raggedbottom to only the content of an environment and not the other parts of the document (in a book). However, it seems that the afterpage command and/or usage of global variables does not work as I intend it to in an environment. In the MWE below, you'll see that the text "extbottomexttop" is printed to the second page so it seems that @textbottom is not read successfully. I tried using \@{textbottom} instead (which I know from other programming languages) but that did not help either.

\documentclass{book}

\usepackage{afterpage}
\usepackage{lipsum}
\newenvironment{chaptertitlepage}{
    \raggedbottom
}{%
    \makeatletter
    \afterpage{\global\let\@textbottom\relax \global\let\@texttop\relax}
    \pagebreak
}

\begin{document}

\begin{chaptertitlepage}
\chapter{First chapter starts here}
It contains information about authors and an abstract which should all fit on the first page.
\lipsum[1-2]
\end{chaptertitlepage}

\section{Introduction}
The other text follows after

\lipsum[3-5]

\end{document}

3
  • no need for afterpage just use \raggedbottom but force a page break with \clearpage at the start and end of the environment Commented Jan 18, 2021 at 12:09
  • and you need to make the definition in the scope of \makeatletter .. \makeatother (putting \makeatletter inside the definition does nothing) Commented Jan 18, 2021 at 12:09
  • but as it is just 1 page you don't need \raggedbottom at all, simply \clearpage to force the page break. Commented Jan 18, 2021 at 12:11

2 Answers 2

0

It seems that you want to force a short (ragged) page break after the environment, so it is enough to call \clearpage

\documentclass{book}


\usepackage{lipsum}
\newenvironment{chaptertitlepage}{\clearpage}{\clearpage}


\begin{document}

\begin{chaptertitlepage}
\chapter{First chapter starts here}
It contains information about authors and an abstract which should all fit on the first page.
\lipsum[1-2]
\end{chaptertitlepage}

\section{Introduction}
The other text follows after

\lipsum[3-5]

\end{document}

enter image description here

2
  • Thanks, this seems the cleanest solution. Could you explain how that works? What does the processor do when it encouters \clearpage which then leads to not being stretched vertically? Commented Jan 18, 2021 at 16:32
  • 1
    @BramVanroy i\clearpage or \newpage is a forced page break and leaves the page short just as \\ or \newline are a forced line break that leaves the line short. Conversely \pagebreak is like \linebreak and would force a page but not do anything special with the page so would be justified page or line if that is the current setting. Commented Jan 18, 2021 at 16:36
1

The code in the question uses command names with @ in the name:

\newenvironment{chaptertitlepage}{
    \raggedbottom
}{%
    \makeatletter
    \afterpage{\global\let\@textbottom\relax \global\let\@texttop\relax}
    \pagebreak
}

The code \newenvironment{...}{...}{...} is parsed immediately, but \makeatletter is executed at a later time, when the environment will be executed. But then, the code is already parsed: \@, 't', 'e', ...

Use \makeatletter earlier during the definition of the environment:

\makeatletter
\newenvironment{chaptertitlepage}{%
    \raggedbottom
}{%
    \afterpage{\global\let\@textbottom\relax \global\let\@texttop\relax}%
    \pagebreak
}
\makeatother

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .