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:
Unbreakable block

I am writing a very simple how-to document with several screenshots. The document flow goes something like this:

A few sentences explaining action 1

\begin{center}
\includegraphics{action_1_screenshot}
\end{center}

A few sentences explaining action 2

\begin{center}
\includegraphics{action_2_screenshot}
\end{center}

However since the screenshots are often large, I sometimes get page breaks between the paragraph and the corresponding screenshot. I want the paragraph to always be on the same page as a screenshot.

I have used \clearpage after each screenshot, but that doesn't quite get what I want. \clearpage would make sure that there is a page break after each screenshot, but I still want multiple screenshots on the same page if they fit. Ideally, I would have something like this to guarantee that two items were on the same page, though wouldn't necessarily always cause a page break:

\begin{samepage}

A few sentences explaining action 2

\begin{center}
\includegraphics{action_2_screenshot}
\end{center}

\end{samepage}

Is something like this possible? I'm not really looking for figures, because those don't tend to work well with longer descriptive paragraphs. Figures seem to be more optimized for a short sentence or sidenote.

share|improve this question

marked as duplicate by lockstep, Gonzalo Medina, Andrey Vihrov, Martin Scharrer Oct 6 '11 at 19:53

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  
Did you try what you have posted? Looks fine to me. –  topskip Oct 6 '11 at 19:45
4  
@Patrick Holy cow, I never tried samepage, I just thought such an environment was wishful thinking on my part. Turns out that it actually exists... –  Phil Oct 6 '11 at 19:52

2 Answers 2

If you put everything together into a {minipage}{\textwidth} environment you ensure that everything is placed on one page. However, this doesn't allow for normal footnotes, which require more work. Also you will get ugly page breaks.

I would rather use figure environments for the screenshots together with \caption and \label so you can \ref-erence them in the text. You can place two \includegraphics into one figure with separate \captions to ensure they are always placed together.

You could also define a samepage environment which uses two zref page labels in the \begin and \end code. Then after one compiler run the \begin code can check if both are on separate pages and cause an \clearpage if not. The code in my answer to Test if a paragraph has a page break in it? could be used for this.

share|improve this answer

The minipage environment is what you're after. That is

\begin{minipage}{\textwidth}

A few sentences explaining action 2

\begin{center}
\includegraphics{action_2_screenshot}
\end{center}

\end{minipage}
share|improve this answer

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