Basically the same as this question, except I don't want to have to remember to write \mynobreakpar (or anything else) everywhere.
How do I set this as the default option for all itemize/enumerate/etc. environments?
Basically the same as this question, except I don't want to have to remember to write \mynobreakpar (or anything else) everywhere.
How do I set this as the default option for all itemize/enumerate/etc. environments?
I don't know if this is overkill but one workaround is by using etoolbox package. I took the liberty of copying Ulrike Fischer's macro from your link.
\documentclass{article}
\makeatletter
\newcommand\mynobreakpar{\par\nobreak\@afterheading}
\makeatother
\usepackage{etoolbox}
\BeforeBeginEnvironment{itemize}{
\mynobreakpar
}
\usepackage{lipsum}
\begin{document}
Some text
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
\lipsum[1-4]
Here is an intervening paragraph. Does this answer your needs? Because the quick brown fox jumps over the head of the lazy dog. And the quick brown fox jumps over the head of the lazy dog.
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
\end{document}
Here's an alternative solution. I would create my own version of the environments for which you want this feature to apply:
\makeatletter
\newcommand\mynobreakpar{\par\nobreak\@afterheading}
\makeatother
\newenvironment{myitemize}{\mynobreakpar\begin{itemize}}{\end{itemize}}
I do not understand why a new paragraph should be lauched before the list. Actually, it seems that you need to take into account the effects of \par to get what you want.
There is only one situation where I do not like page breaks before lists. Furthermore, I do not like list tags not being aligned. This has led to the following.
\makeatletter
\newcommand{\nolisttopbreak}{\vspace{\topsep}\nobreak\@afterheading}
\makeatother
\newenvironment{listproof}[1][\proofname]{\begin{proof}[#1]\mbox{}\nolisttopbreak}{\end{proof}}
As you can see, there is no paragraph break anywhere.
\@afterheading is probably just what a \begin{proof} generates, so that the first list item is started right after the \proofname command without any linebreak or vertical space in between.
Using my own answer in question referenced by asker, you can redefine item macro to let it work for lists environments. It's absolutely transparent, you don't event have to using own environment.
\let\nativeitem\item
\renewcommand{\item}{
\begin{samepage} % prevent page-break before list enviroment
\nativeitem\ % character needed after \item
\end{samepage}\pagebreak[2] % page-break opportunity after (and only after) every item
}
\item), you could use \mbox{}.
– Werner
Mar 28 '17 at 22:24
etoolboxbefore, +1 thanks. – user541686 Dec 08 '12 at 04:29