Page LayoutHow to avoid orphans when creating environment?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

How to avoid orphans when creating environment?

Post by yoyoimut »

Orphan
Orphan
orphan.jpg (190.35 KiB) Viewed 2495 times
Hi,


I am creating an environment just for the sake of illustration according to the following code:

Code: Select all

\documentclass{book}
\usepackage[a4paper,vmargin=7cm]{geometry}
\usepackage{multido,lipsum}

\newcounter{exercise}
\newenvironment{Exercise}{%
\refstepcounter{exercise}%
\vspace{10pt}\par\noindent%
\textbf{Exercise} \theexercise%
\begin{itshape}%
\par\noindent\ignorespaces}
{\end{itshape}\vspace{10pt}\par}


\begin{document}
\multido{\i=1+1}{30}{%
\begin{Exercise}
\lipsum[1-5]
\end{Exercise}}
\end{document}

My question is

1. how to force latex to avoid generating orphan?
2. is theorem environments (from amsthm.sty) orphan-free?

Thank you in advance.



Yuko.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

How to avoid orphans when creating environment?

Post by kaiserkarl13 »

I'm not sure if this works in all situations, but it solved the problem for your example.

Place \nopagebreak in front of the \par command in the definition of your environment:

Code: Select all

\newenvironment{Exercise}{%
   \refstepcounter{exercise}%
   \vspace{10pt}\par\noindent%
   \textbf{Exercise} \theexercise%
   \begin{itshape}%
   \nopagebreak\par\noindent\ignorespaces}
{\end{itshape}\vspace{10pt}\par}
To prevent orphans ("clubbed lines") and widows in the body text, use the following commands:

Code: Select all

\clubpenalty=10000
\widowpenalty=10000
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Re: How to avoid orphans when creating environment?

Post by yoyoimut »

Thanks kaiserkarl13, well done!


regards,

Yuko
Post Reply