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.

I'm using the overpic environment to include figures, and the memoir class to add captions. How do I force the caption to always stay on the same page as its corresponding figure?

Below is my MWE. If the image is big enough, the caption appears on the following page.

\documentclass[11pt,a4paper]{memoir}

\usepackage{fouriernc} % use the Arev font
\usepackage{overpic} % use the overpic package

% caption images outside the figure environment
\newfixedcaption{\figcaption}{figure} \captionnamefont{\normalfont} \captiontitlefont{\normalfont}

\begin{document}

This is some text.

\begin{center}
\begin{overpic}[width=0.9\textwidth]{./myfig.pdf}
\put(10, 10){Here is text superimposed on the figure.}
\end{overpic}
\figcaption{I want this caption on the same page as the corresponding figure.}
\end{center}

\end{document}
share|improve this question

1 Answer 1

up vote 8 down vote accepted

Since there is no connection between the overpic environment and \figcaption, they can get separated. Also, the center environment doesn't keep things together (in a box, that is), but merely acts as a switch to change the justification of whatever it contained within.

The following should result in the correct behaviour:

\noindent
\begin{minipage}{\textwidth}
  \centering
  \begin{overpic}[width=\textwidth]{tiger.pdf}
    \put(10, 10){Here is text superimposed on the figure.}
  \end{overpic}
  \figcaption{I want this caption on the same page as the corresponding figure.}
\end{minipage}

It boxes the contents in a minipage of full width (\textwidth), centres the contents (\centering) and avoids a paragraph indent (\noindent) since it is set in horizontal mode (and is therefore considered a paragraph).

It does not, however, avoid overfull boxes from occurring if the contents of the minipage oversteps the text block boundaries.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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