環境の最後の 3 行でページ区切りを防ぐにはどうすればよいですか?

環境の最後の 3 行でページ区切りを防ぐにはどうすればよいですか?

最後の段落の最後の 3 行でページ区切りが許可されないコンテンツ環境を作成したいと考えています。

環境内のテキストの最後の 3 行がページ境界に達する場合、下から 4 行目の後にページ区切りが発生します。

環境外では、改ページの通常の動作は変更しないでください。

環境には通常のテキストのみが含まれますが、左右の余白が拡大されます。インライン数式もいくつか表示される可能性がありますが、それだけです。

\documentclass{scrartcl}

\usepackage{lipsum}

\newenvironment{env}{%
    \begin{addmargin}{2em}%
}{%
    \end{addmargin}
}%


\begin{document}
\lipsum[1-3]

\begin{env}
    \lipsum[1]
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This last lines should not be broken to the next page.
    This last lines should not be broken to the next page.
    This last lines should not be broken to the next page.
\end{env}
\end{document}

編集:

私が何を達成しようとしているのか、はっきり説明できるかどうかはわかりません。通常、最後の行が正確にどこから始まるのかはわかりません。むしろ、段落の最後の行が次のページに分割されるのを防ぐだけでなく、環境内の最後の 3 行のテキストが、{env}実際のページでも次のページでも常に一緒に残るようにすることが目的です。

答え1

\widowpenalties; は次のように使用できます。

\widowpenalties 3 10000 10000 0

最後の3行の間には10000のペナルティを追加し、それより前の行の間には何も追加しません。段落内での改ページを回避するにはどうすればよいですか?

\documentclass{scrartcl}

\usepackage{lipsum}

\newenvironment{env}
 {\begin{addmargin}{2em}\widowpenalties 3 10000 10000 0 }
 {\end{addmargin}}


\begin{document}
\lipsum[1-3]

\begin{env}
    \lipsum[1]
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This is just some filler text, to reach the page break.
    This last lines should not be broken to the next page.
    This last lines should not be broken to the next page.
    This last lines should not be broken to the next page.
\end{env}
\end{document}

ここに画像の説明を入力してください

関連情報