TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the following command in my class (thanks to this answer):

                                {3.25ex \@plus1ex \@minus.2ex}%

Now I had the problem that the section title happened to be the last thing on a page, and its corresponding text ended up in the next page. How to change this definition to prevent this problem to happen? I tried adding a \nopagebreak as last thing before }, with no success...

share|improve this question

closed as unclear what you're asking by Werner, Speravir, Jesse, ChrisS, OSjerick Jan 10 '14 at 5:24

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

What you ask for is the default behavior of the \@startsection command. Also the definition you exhibit for \section puts the section title on the same line as the text of the first paragraph, which contradicts your description. So please provide a minimal working example (MWE) document that exhibits this problem. – Dan Dec 5 '13 at 5:39

You could use the titlesec package to redefine the \section command. For example, it says:

If you dislike typing the full skip values, including the plus and minus parameters, an abreviation *n is provided (where n is an integer). In the beforesep argument this is equivalent to n ex with some stretchability and a minute shrinkability. In the aftersep some strechability (smaller) and no shrinkability. Thus, you can write


Edit: The following example I believe successfully keeps the \section with the text below it.


\usepackage{lipsum} % generate filler text



\section{Section 1}


\section{Section 2}


share|improve this answer
And how those spacing settings will effect the prevention of page break just after the title? – lvella Dec 5 '13 at 1:46
See edited post with new example – I Like to Code Dec 5 '13 at 2:04
I think you misunderstood me (or maybe I was not clear enought) you managed to get the title on the same line of the text; that is not what I wanted. I wanted the title on one line, followed by the text paragraph below it, but should have a way to tell LaTeX the title and the text are semantically related so the title must not end a page so its text will start next. It is like using ~ to prevent the line break algorithm to place two words on separated lines... – lvella Dec 5 '13 at 2:22
Ah. When I compiled the example using the code which you originally provided in the question, in the output, the text followed the title like the \paragraph command. – I Like to Code Dec 5 '13 at 2:35

I didn't understand why exactly it worked, but I managed to do it. I just had to add \leavevmode at the beginning of the definition:

                                {3.25ex \@plus1ex \@minus.2ex}%

If you know why it works or whether it as the "right" solution, please tell me!

EDIT: it seems it doesn't affect all cases where a page break could happen, so it is not a complete solution.

share|improve this answer

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