I want to illustrate my examples, which are set in a theorem-like environment. Is it possible to wrap the text and equations around the figures? I have read about several packages but I can't get them to work in a theorem. Am I doing something wrong?
3 Answers
The wrapfig package won't behave well with theorem-like structures created with amsthm or ntheorem. The cutwin package can be used with those theorem-like structures (see my example below) as long as only text is involved. However, none of those packages interacts well with displayed math.
A little example of the text of a theorem-like structure wrapped around a figure with caption, using the cutwin package:
\documentclass{article}
\usepackage{cutwin}
\usepackage[demo]{graphicx}
\usepackage{lipsum}
\usepackage{amsthm}
\usepackage{caption}
\captionsetup{singlelinecheck=no}
\newtheorem{exam}{Example}
\begin{document}
\renewcommand\windowpagestuff{%
\includegraphics[height=4cm, width=5cm]{figure}
\captionof{figure}{A test figure.}
}
\opencutleft
\begin{exam}
\begin{cutout}{2}{0pt}{0.5\linewidth}{13}
\lipsum[1]
\end{cutout}
\end{exam}
\lipsum[1]
\end{document}

- 54,637
- 505,128
-
This doesn't work at all in many environments that I use. For example in the springer lncs example environment this glitches and overwrites paragraphs on top of others. – Arlen Cox Feb 22 '14 at 18:30
-
@ArlenCox well, and what did you expect? Classes which are not the standard ones redefine a lot of things. Feel free to open a new question with that class or contact the author/maintainer of the class and ask for a solution there. – Gonzalo Medina Feb 22 '14 at 23:13
-
Worked for me, is there a way to have different pictures for different examples? – ViktorStein Jan 10 '19 at 20:37
I don't know the cutwin package but it's possible to use it with the picins. This package is not actually in TeXLive (we can find it now here).
I use windowpagestuff from the cutwin package to stock the picture with the caption, then I get the width of the picture. It's not sure that all of this stuff is robust but it's interesting to try ...
\documentclass{scrartcl}
\usepackage[]{graphicx}
\usepackage{lipsum}
\usepackage{amsthm}
\usepackage{caption}
\usepackage{picins}
\usepackage{microtype}
\usepackage{cutwin}
\newtheorem{exam}{Example}
\newbox\mybox
\newdimen\myboxwidth
\newcommand\addpicture[3]{%
\setbox\mybox=\hbox{\includegraphics[scale=#3]{#2}}
\myboxwidth\wd\mybox
\renewcommand\windowpagestuff{%
\includegraphics[scale=#3]{#2}
\captionof{figure}{A test figure.}}
\parpic[#1]{%
\begin{minipage}{\myboxwidth}
\windowpagestuff
\end{minipage}
} }
\begin{document}
\begin{exam}
\lipsum[1]
\addpicture{s}{tiger.pdf}{0.2}
\lipsum[1]
\end{exam}
\end{document}

- 95,075
-
And with this approach you can use displayed math environments (
equation,align, etc.); at least that's why my tests suggest. – Gonzalo Medina Apr 03 '11 at 16:10
I tweaked @Altermundus' solution, which does indeed work inside theorems with maths:
\RequirePackage{xparse, graphicx, caption, picins}
\DeclareDocumentCommand \addpic{O{0.4\textwidth} m g}{\parpic[r]{%
\begin{minipage}{#1}
\includegraphics[width=\textwidth]{#2}%
\IfNoValueTF{#3}{}{\captionof{figure}{\footnotesize #3}}
\end{minipage}
}}
Now I can call addpic using addpic{filename}, addpic[width]{filename}, addpic{filename}{caption}, or addpic[width]{filename}{caption}.
- 6,337