1

I'm trying to wrap an image within a linguex bullet, but the image does not compile.

\documentclass{article}
\usepackage{linguex, graphicx, wrapfig}

\begin{document}

\ex. bla bla bla \begin{wrapfigure}{r}{0.5\textwidth}\includegraphics[width=0.5\textwidth]{image}\end{wrapfigure} 

\end{document}

Notice that I need the wrapfigure environment to be on the same line as the \ex. argument, otherwise it wouldn't compile. I feel like that's some sort of incompatibility between the two packages, but does anybody know if there is a way-around?

Thanks!

RobertP.
  • 741

1 Answers1

2

There are a few solutions around for placing figures in list environments. The following uses the answer published here: Will it ever be possible to use wrapfig with an enumerate or itemize environment?

The only difference is the use of the \ex macro versus the enumerate environment. Quoting from the referenced solution:

It is possible by putting the wrapfigure into a parbox or minipage as is mentioned in some of the duplicates of this question. However those methods usually fix vertical spacing issues by manually inserting \vspace with hand picked values. This solution works automatically by using a strut (\strut). The strut places the baseline of the first text line at a specified distance from the top of the minipage. Then adjustbox is used to place the top of the minipage exactly that amount above the outer baseline.

The MWE and result are as follows:

\documentclass[a4paper,12pt]{article}
\usepackage{linguex, graphicx, wrapfig}
\usepackage[margin=3cm]{geometry}
\usepackage{lipsum}
\usepackage{adjustbox}
\usepackage{capt-of}

\newlength{\strutheight}
\settoheight{\strutheight}{\strut}

\begin{document}

% From https://tex.stackexchange.com/questions/59101/will-it-ever-be-possible-to-use-wrapfig-with-an-enumerate-or-itemize-environment/309454#309454
\ex. \begin{adjustbox}{valign=T,raise=\strutheight,minipage={1.0\linewidth}}
        \begin{wrapfigure}{r}{0.5\linewidth}
            \centering
            \includegraphics[width=0.5\linewidth]{example-image-a}
            \captionof{figure}{My caption}
        \end{wrapfigure}% 
        \strut{}\lipsum[2]
    \end{adjustbox}

\end{document}

enter image description here

EDIT

This is a response to OP's comment:

Is it then possible to have a figure wrapped in more than one \ex. environment?

I have to guess a bit to interpret what is requested. Here is an interpretation with multiple figures at different levels of environments.

enter image description here

This is the code:

\documentclass[a4paper,10pt]{article}
\usepackage{linguex, graphicx, wrapfig}
\usepackage[margin=3cm]{geometry}
\usepackage{lipsum}
\usepackage{adjustbox}
\usepackage{capt-of}

\newlength{\strutheight}
\settoheight{\strutheight}{\strut}

\begin{document}

% From https://tex.stackexchange.com/questions/59101/will-it-ever-be-possible-to-use-wrapfig-with-an-enumerate-or-itemize-environment/309454#309454
\ex. \lipsum[2]
\a. \begin{adjustbox}{valign=T,raise=\strutheight,minipage={1.0\linewidth}}
        \begin{wrapfigure}{r}{0.5\linewidth}
            \centering
            \includegraphics[width=0.5\linewidth]{example-image-a}
            \captionof{figure}{My caption}
        \end{wrapfigure}% 
        \strut{}\lipsum[2]
    \end{adjustbox}
\b. \begin{adjustbox}{valign=T,raise=\strutheight,minipage={1.0\linewidth}}
    \begin{wrapfigure}{r}{0.5\linewidth}
        \centering
        \includegraphics[width=0.5\linewidth]{example-image-a}
        \captionof{figure}{My caption}
    \end{wrapfigure}% 
    \strut{}\lipsum[2]
    \end{adjustbox}
    \a. \begin{adjustbox}{valign=T,raise=\strutheight,minipage={1.0\linewidth}}
        \begin{wrapfigure}{l}{0.5\linewidth}
            \centering
            \includegraphics[width=0.5\linewidth]{example-image-a}
            \captionof{figure}{My caption}
        \end{wrapfigure}% 
        \strut{}\lipsum[2]
    \end{adjustbox}
    \b.\lipsum[2]

\end{document}
Ross
  • 5,656
  • 2
  • 14
  • 38
  • Nice! Is it then possible to have a figure wrapped in more than one \ex. environment? – RobertP. Jan 22 '17 at 04:09
  • @RobertP If I interpret your question correctly, the answer is yes. Other solutions are possible using the cutwin, which has the advantage of determining where the figure is placed in the itemized paragraph. However, if those types of customizations are not required, this works out-of-the box in all the list environments and classes (including Beamer) where I have used it. – Ross Jan 22 '17 at 05:00