4

Possible Duplicate:
Unbreakable block

I have a block of text (possibly comprising many paragraphs) near the end of a page. The page break is being inserted in the middle of this block--how do I prevent that? (How do I tell LaTeX that this block of text needs to always stay together on the same page?)

This question should apply to all formats, but in my case I am using the memoir class, and am willing to include any necessary packages.

jamaicanworm
  • 29,114

1 Answers1

7

If you wrap the contents within a minipage then TeX will put that block on the next page if it does not fit on the current page.

In the example below, the text in red is on Page 2. But if you remove the minipage environment by commentig out the \begin{minipage}{\linewidth} and \end{minipage}, then the text will be on Pages 1 and 2.

Note:

Code:

\documentclass{article}
\usepackage{lipsum}% for dummy text
\usepackage{xcolor}
\begin{document}
\lipsum[1-4]% dummy text to get towards bottom of page
\noindent
\begin{minipage}{\linewidth}% Following stays together
    \color{red}
    \lipsum[1-2]
\end{minipage}
\end{document}
Peter Grill
  • 223,288
  • 1
    The interline spacing after the minipage won't be uniform. – egreg Feb 17 '12 at 22:12
  • 1
    and the minipage will set the glue (vertical stretch if any) so that it doesn't participate with other glue on the page. – Frank Mittelbach Feb 17 '12 at 22:58
  • Thanks! What is the difference between \begin{minipage}{\lindwidth} (what you wrote) and \begin{minipage}{\textwidth}? – jamaicanworm Feb 18 '12 at 02:33
  • 2
    Basically \textwidth is the full width on the page between the margins, where \linwidth adjusts for multiple columns, lists, etc. See difference between textwidth linewidth and hsize for a more detailed discussion. – Peter Grill Feb 18 '12 at 03:14
  • As I just commented here http://tex.stackexchange.com/q/38345/9757, is it possible to define a macro for the fullwidth environment, so that whenever I write \begin{fullwidth}, LaTeX does \begin{minipage}{\linewidth} \begin{fullwidth}[width=\linewidth+4cm] \medskip; and whenever I write \end{fullwidth}, LaTeX does \medskip \end{minipage} \end{fullwidth}? Thanks! – jamaicanworm Feb 18 '12 at 16:20
  • 1
    @jamaicanworm: This seems like a new question. – Peter Grill Feb 18 '12 at 16:30