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.

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}
share|improve this question
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. –  David Carlisle 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. –  Marius Hofert Mar 31 '13 at 9:49

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer
1  
Perfect as usual, many thanks for sharing, David. One comment (for future reference): the \blindtext[1] right after \end{wrapfigure} is crucial. –  Marius Hofert Mar 31 '13 at 10:23

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.