Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
Avoiding page breaks shortly after section/subsection headings

Imagine that I've got a \section (or \subsection, \subsubsecion, \paragraph) at the end of the page X: in this case, even if a single row of the section can fit into the page, the section is shown into the page X.

Since in this case I'd prefer showing the section in the new page, I have to manually insert a \newpage before the section.

How is it possible to specify that at least N rows of the section have to be shown into the page X (and in the other case, the entire section has to be shown on the page X+1)?

share|improve this question

marked as duplicate by lockstep, Mico, diabonas, Harish Kumar, percusse Sep 10 '12 at 22:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
Please have a look at: pagebreak if only 1/4th of the page left. Please tell us the answer there helps, so we could close this question as a duplicate. –  Stefan Kottwitz Sep 10 '12 at 8:57
    
I wouldn't bother with such problems until the document is in its final form and only typographical adjustments are to be made. –  egreg Sep 10 '12 at 9:01
1  
In addition to needspace package, look at What are penalties and which ones are defined? and specially to \clubpenalty. –  Fran Sep 10 '12 at 9:06
add comment

1 Answer 1

Thanks, I've solved in this way: 1/4 of the page must be available for sections; 15% of the page for subsections.

Here is the code.

% new sections and subsection not at the end of the page
\usepackage{needspace}
\makeatletter
\renewcommand{\section}{\needspace{.25\textheight} \@startsection{section}{1}{0mm}
  {\baselineskip}
  {\baselineskip}{\Large\bfseries\scshape}}
\renewcommand{\subsection}{\needspace{.15\textheight} \@startsection{subsection}{1}{0mm}
  {\baselineskip}
  {\baselineskip}{\large\bfseries\scshape}}
\makeatother
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.