How to avoid heading orphan?

I want to get rid of pages ending with a heading title only. I want at least 2 text rows following the heading title to make a better look.

What is the exact value to be passed to \Needspace*{} to avoid this heading orphan?

-
By default, pages should not end with a heading in LaTeX. Show a minimal example as evidence to the contrary. –  lockstep Jan 24 '11 at 7:15
@xport: I think it was a bad idea to change your user name beyond recognition. On this site, people just got to know you under the name xport. –  Hendrik Vogt Jan 31 '11 at 17:47
@xport: If one of the answers solved your problem, please consider accepting an answer so that your question moves off the "Unanswered" list. –  Hendrik Vogt Mar 2 '11 at 16:46
@Hendrik: DONE. –  xport Mar 7 '11 at 17:26
@xport: Ah, your back. While you're here, can you please also rename yourself to "xport", please? Thanks! –  Hendrik Vogt Mar 7 '11 at 17:37

2 Answers

The normal way to control orphans is to adjust the \clubpenalty variable. Try to set it to an higher value. See http://www.tex.ac.uk/cgi-bin/texfaq2html?label=widows for more information.

If you want to use \Needspace*{} I would assume that 4\baselineskip is reasonable for the heading title plus two text rows. I'm simply counting the bigger heading title line twice, therefore the factor 4. You could experiment with factors between 3 and 4. The exact amount is of course dependent on the kind of heading that follows.

-
I don't think that \clubpenalty is relevant here: It controls how much first lines of paragraphs at the bottom of a page a discouraged. The present post is about single line headings. –  Hendrik Vogt Jan 24 '11 at 11:19
Ok, another thing learnt. –  Martin Scharrer Jan 25 '11 at 10:44

I don't know if this is what you're looking for but you could always use \begin{samepage} and \end{samepage} to keep together the stuff that you don't want to be separated.

There should be a penalty counter though that omits this dreadful use of the samepage environment. Read this question for more info on the how to discourage latex in breaking pages after your headings.

Add the following to your preamble and you should be fine:

\usepackage{etex}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\@afterheading}%
{\clubpenalty \@M}{\clubpenalties 3 \@M \@M 0}{}{}
\patchcmd{\@afterheading}%
{\clubpenalty \@clubpenalty}{\clubpenalties 2 \@clubpenalty 0}{}{}
\makeatother

-
Welcome to tex.sx! Note that you don't have to (and shouldn't) sign with your name since it automatically appears in the lower right corner of your post. –  Hendrik Vogt Jan 31 '11 at 17:45
haha ok. I'll try to keep that in mind. –  romeovs Feb 1 '11 at 22:56