This is not a duplicate of preventing a pagebreak.
What I want to achieve
Consider an itemize
environment, where one of the \item
s are split over the bottom of one page and the beginning of the next:
I want the \item
(alternatively the entire itemize
environment) to go on top of the next page instead of being split over two pages.
However, if there is any (reasonable) way to put it on the current page, then it should prioritize that.
I want this to be done automatically, so without e.g. needspace
package.
What I've tried
I suspect this will be done with penalties. I've been playing around with the ones in the \samepage
definition as well as the ones listed in this answer.
For example \@itempenalty\@M
does not work, which makes me a little puzzled.
It might just be that I don't quite understand what the penalties actually do. I understand it so that if a certain penalty is high then the interpreter will attempt to avoid breaking at this penalty. What I don't understand is how to encourage the page break iff there is no way that it can insert the content (under normal restrictions).
Code
I'm working on a package, and this is just a MWE.
The itemize splits across pages, and in this example there is no room, so I want the itemize
environment (I'm also fine with just the \item
in question) to jump to the next page. (I added a \makeatletter
so you don't have to.
\documentclass{article}
\usepackage{lipsum}
\setlength{\parindent}{0em}
\makeatletter
\begin{document}
\lipsum[1-4]
\bgroup
%\bgroup is okay here, right?
% (Then the penalties should go back at \egroup?)
%% Magic, amazing penalty code can go here. %%
%% ... or wherever it fits best ... %%
\begin{itemize}
\item\lipsum[10-12]
\end{itemize}
\egroup
\end{document}
This is not really a question about penalties, although I wouldn't mind links or explanations that would clarify how the compiler (i.e. pdftex) deals with penalties.
Thanks in advance, guys :)
Feel free to suggest, or do, edits to the title so it's more to the core of the problem. I feel a little on thin ice with this title?
itemize
environment in aminipage
, to prevent it breaking up.minipage
in your MWE, you need to use the[b]
option, to get the exit spacing right. You may need to add a\strut
to you first\item
. Else, use the[t]
option and add a\strut
at the end of the last\item
.\filbreak