3

This must be easy but I can't figure out why the "figure" is not put at the correct spot (in the example) with `wrapfigure'.

\documentclass{article}

\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{blindtext}
\newtheorem{example}{Example}[section]

\begin{document}
\begin{example}
  \blindtext[1]
  \begin{wrapfigure}{r}{0.5\textwidth}
    \framebox[0.5\textwidth]{\rule{0pt}{100pt} Figure}
  \end{wrapfigure}
  \blindtext[1]
\end{example}
\blindtext[2]
\end{document}
2
  • 2
    internally theorem is implemented as a one item list and the wrapfig doc says: You must not specify a wrapfigure in any type of list environment or or immediately before or immediately after one. Mar 31 '13 at 9:48
  • Hi David, many thanks. I tried an alternative with a minipage but that didn't come out nice. Do you have a suggestion in this case? I just have an example environment and would like to let text float around a (right-aligned, 50% textwidth) figure. Mar 31 '13 at 9:49
4

Internally theorems are a one item list and it is a documented restriction that wrapfig does not work in lists.

However theorems don't usually use too much of the list structure so with care you can make it work, especially if, as here, it is not the first paragraph (where you have the extra complication of the heading which is implemented as a list item)

enter image description here

\documentclass{article}

\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{blindtext}
\newtheorem{example}{Example}[section]

\begin{document}
\begin{example}
  \blindtext[1]

  {\makeatletter
\let\par\@@par
\par\parshape0
\everypar{}\begin{wrapfigure}{r}{0.5\textwidth}
    \framebox[0.5\textwidth]{\rule{0pt}{100pt} Figure}
  \end{wrapfigure}
  \blindtext[1]\par}%
\end{example}
\blindtext[2]
\end{document}
1
  • 1
    Perfect as usual, many thanks for sharing, David. One comment (for future reference): the \blindtext[1] right after \end{wrapfigure} is crucial. Mar 31 '13 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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