Page Layoutnot enough space for chapter

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
kvaso
Posts: 9
Joined: Sun Apr 24, 2011 4:49 pm

not enough space for chapter

Post by kvaso »

Hi,
sometimes happens to me, that a chapter title is at the very bottom of the page and the content of the chapter is on the new page.
This does not look nice. Is there any way, how to tell latex to move the whole chapter to the new page, if there is not enough space in the current page?

I can use \pagebreak, but this "manual" aproach can be tricky...
also I googled samepage, but I am looking for something that can be applied globally on the whole document

thanks a lot

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

not enough space for chapter

Post by Stefan Kottwitz »

It cannot happen with a real chapter, i.e. with \chapter. Do you mean \section? Or which command shows the problem here?

Stefan
LaTeX.org admin
kvaso
Posts: 9
Joined: Sun Apr 24, 2011 4:49 pm

Re: not enough space for chapter

Post by kvaso »

yes, sorry - I meant section
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

not enough space for chapter

Post by Stefan Kottwitz »

Yes, \chapter starts a new page by itself and is always on top. Normally a section heading should also not be at the end of a page. Do you have a small example document showing such a behavior, with your class and your settings resp. preamble?

Stefan
LaTeX.org admin
kvaso
Posts: 9
Joined: Sun Apr 24, 2011 4:49 pm

Re: not enough space for chapter

Post by kvaso »

unfortunately I am not able to create an example of this behaviour...
but here is a sample document with my preamble and it shows what I want to change in latex settings - there is a section with only 2 lines of content and then a page break
Attachments
sample.tex
(2.85 KiB) Downloaded 268 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

not enough space for chapter

Post by Stefan Kottwitz »

Text lines at the end are normal - just a section title at the end would be strange.

Well, in any case you could use the needspace package, even if you don't like this case of the example.

Code: Select all

\usepackage{needspace}
...
\needspace{4\baselineskip}
\section{test}
Just specify the required space, here I said 4 lines, but you could give it in ex, pt, cm or any unit as well.

Stefan
LaTeX.org admin
kvaso
Posts: 9
Joined: Sun Apr 24, 2011 4:49 pm

not enough space for chapter

Post by kvaso »

needspace looks like it is what I want, but is there any way, how to define it once in preamble, so I don't need to use needspace before each section?

thanks a lot
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

not enough space for chapter

Post by Stefan Kottwitz »

Sure, you could redefine \section, hook into a related macro, or patch it. Fore example:

Code: Select all

\usepackage{needspace}
\usepackage{etoolbox}
\patchcmd{\section}{\@startsection}{\needspace{4\baselineskip}\@startsection}{}{}
Stefan
LaTeX.org admin
kvaso
Posts: 9
Joined: Sun Apr 24, 2011 4:49 pm

Re: not enough space for chapter

Post by kvaso »

thanks a lot - the wonderful world of latex keeps me amazed all the time :D
Post Reply