# How to force a picture's location and still use overpic

I want to insert a picture, and use overpic to label it, in between two paragraphs of text, like so:

Here is my first paragraph of text.
\begin{figure}[htb] \centering
\begin{overpic}[width=0.5\textwidth]{./figure/mypicture.pdf}
\put(20, 20){$A$}
\end{overpic}
\caption{This is mypicture.pdf, with the label $A$.}
\end{figure}
Here is my second paragraph of text.
In order to understand this paragraph, you first need to see the picture.


But depending on the content of those paragraphs, and on other pictures that are inserted before or after them, mypicture.pdf doesn't always end up in the right place. Is there a way to force it to be there (as in \includegraphic), while still being able to use overpic?

-
Just use center instead of figure (and don't say \centering). –  egreg Dec 17 '11 at 23:24
Then should I also get rid of [htb]? How can I still insert a caption? –  jamaicanworm Dec 17 '11 at 23:31

You can use simply a center environment instead of the floating figure environment; if a caption is required, you can use \captionof from the caption or capt-of packages:

\documentclass{book}
\usepackage{graphicx}
\usepackage{overpic}
\usepackage{caption}

\begin{document}

Here is my first paragraph of text.
\begin{center}
\begin{overpic}[width=0.5\textwidth]{./figure/mypicture.pdf}
\put(20, 20){$A$}
\end{overpic}
\captionof{figure}{This is mypicture.pdf, with the label $A$.}
\end{center}
Here is my second paragraph of text.
In order to understand this paragraph, you first need to see the picture.

\end{document}


If the memoir document class is used, then there's no need to use additional packages to produce the caption outside a floating environment, since the class has a built-in mechanism (the \newfixedcaption command) to this effect:

\documentclass{memoir}
\usepackage{graphicx}
\usepackage{overpic}

% we declare a new type of caption for captioning images outside
% the figure environment,
\newfixedcaption{\figcaption}{figure}

\begin{document}

Here is my first paragraph of text.
\begin{center}
\begin{overpic}[width=0.5\textwidth]{./figure/mypicture.pdf}
\put(20, 20){$A$}
\end{overpic}
\figcaption{This is mypicture.pdf, with the label $A$.}
\end{center}
Here is my second paragraph of text.
In order to understand this paragraph, you first need to see the picture.

\end{document}

-
I'm using the memoir class, and I get a warning when I try to include \usepackage{caption}--it also gives lots of errors, since I'm assuming this caption environment overrides the memoir default. Is there any way to resolve this conflict? Or should I just use the capt-of package instead? Thanks! –  jamaicanworm Dec 17 '11 at 23:58
@jamaicanworm: please see my updated answer. Please do always mention in your questions the document class used; this information (as you have just seen) can be crucial ;-) –  Gonzalo Medina Dec 18 '11 at 0:08
@jamaicanworm: a lot of information you forgot to mention! I did some tests, but couldn't reproduce the problem you just mention. Since the particular problem in this question has been solved, I suggest you to open a new question (perhaps indicating that it's a follow-up to this one) with the new problem (and adding a MWE). –  Gonzalo Medina Dec 18 '11 at 0:16
@jamaicanworm: \usepackage[demo]{graphicx} will replace all your figures with black rectangles; it's useful if you don't have the actual files containing the images, so it's used a lot in answers about figures. In your actual code you don't use that option (sorry for using it in my code without a warning; I will remove it). –  Gonzalo Medina Dec 18 '11 at 0:18
@jamaicanworm: and you already have an answer ;-) –  Gonzalo Medina Dec 18 '11 at 0:40