2

If

\paragraph{abc}
text text text text text text text text text text ... text

is on the bottom of page \paragraph stays at the bottom while the content is moved to top of the next page. How to force \paragraph to also get moved to the top of next page instead of standing alone at the bottom of last page.

6
  • \pagebreak\paragraph{abc}
    – Sveinung
    Dec 17, 2013 at 18:03
  • 2
    Possible duplicate: How to keep Heading together with text?
    – Werner
    Dec 17, 2013 at 18:07
  • the real question is what else do you have on the page that is causing the heading to separate from the text (since latex already makes it infinitely bad to break after the line with abc.) As always you should provide a complete document that shows the problem. Dec 17, 2013 at 20:21
  • 1
    To people voting that it's a duplicate, note \paragraph is an inline heading and the referenced question is about \section which is a display heading. the situations are not unconnected, but not the same either. Dec 17, 2013 at 20:23
  • it sounds like you may have \clubpenalty set rather low, and no stretch allowed in the space before \paragraph. not nearly enough is known to be able to answer this question in its present form. Dec 17, 2013 at 20:55

2 Answers 2

7

Please always post complete documents, especially in this case where the problem is in code you have not shown.

LaTeX already makes it an infinitely bad place to break after the heading, so if it does break there, something else on the page made the constraints infeasible, and all options were infinitely bad.

Consider

\documentclass{article}

\setlength\textheight{5cm}
\begin{document}

a\\b\\c\\d\\e\\f\\g\\h


\paragraph{abc}
text text text text text text text text text text ... text
text text text !!text text text text text text text ... text
text text text text text text text text text text ... text
text text text text text text text text text text ... text

\end{document}

enter image description here

If you push the text down 1 line:

\documentclass{article}

\setlength\textheight{5cm}
\begin{document}

a\\b\\c\\d\\e\\f\\g\\h\\i


\paragraph{abc}
text text text text text text text text text text ... text
text text text !!text text text text text text text ... text
text text text text text text text text text text ... text
text text text text text text text text text text ... text

\end{document}

TeX does not break between the abc heading and the !! line, it takes the whole thing over including the heading:

enter image description here

Note to do this it has to be allowed to stretch the white space enough to account for the line taken over. The stretchy space of the paragraph heading itself and.or between paragraphs should be enough, but it all depends on what class and settings you have used, but haven't revealed.

3

There are different ways of keeping it together:

  • use the \needspace command from the needspace package
  • put your paragraph in a \vbox that won't be break
  • use the samepage package

For the needspace command:

\usepackage{needspace}

\begin{document}
...
\needspace{5em}
\paragraph{A paragraph}
Some more text

\end{document}

For the \vbox strategy:

\begin{document}
...
\vbox{
\paragraph{A paragraph}
Some more text
}
\end{document}

For the samepage package:

\usepackage{samepage}

\begin{document}
...
\begin{samepage}
\paragraph{A paragraph}
Some more text
\end{samepage}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .