![如何强制图片的位置并仍然使用 overpic](https://linux22.com/image/243830/%E5%A6%82%E4%BD%95%E5%BC%BA%E5%88%B6%E5%9B%BE%E7%89%87%E7%9A%84%E4%BD%8D%E7%BD%AE%E5%B9%B6%E4%BB%8D%E7%84%B6%E4%BD%BF%E7%94%A8%20overpic.png)
我想overpic
在两段文字之间插入一张图片并用它来标记它,如下所示:
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.
但是,根据这些段落的内容以及插入在它们之前或之后的其他图片,mypicture.pdf 并不总是出现在正确的位置。有没有办法强制它出现在那里(如\includegraphic
),同时仍然能够使用overpic
?
答案1
您可以简单地使用center
环境而不是浮动figure
环境;如果需要标题,您可以使用或\captionof
包:caption
capt-of
\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}
如果memoir
使用文档类,则无需使用额外的包在浮动环境之外生成标题,因为该类具有内置机制(命令\newfixedcaption
)来实现此效果:
\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}