1

I'm doing a poster, using a the a0poster style, and I was trying to wrap a itemize list around a figure. I tried the wrapfigure package, but I gathered it doesn't work with itemize lists, so I tried floatflt, which is supposed to work fine with lists (provided you use \fltitem). My MWE is as follows:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{floatflt}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage[margin=2cm]{geometry}

\setlength\parindent{0pt}

\begin{document}
\lipsum[1]
\begin{multicols}{2} 

\section{Introduction}
\lipsum[2-3]

\begin{floatingfigure}[r]{0.5\columnwidth}
\centering
\includegraphics[width=0.48\columnwidth]{universe.jpg}
\caption{very very very very very very very very very very very very very very very very long caption}
\label{fig:example}
\end{floatingfigure}

\begin{itemize}
    \fltitem{one very very very very very long text}
    \fltitem{two very very very very very long text}
    \fltitem{three very very very very very long text}
\end{itemize}
\lipsum[4-7]

\end{multicols}
\end{document}

which results in (notice the absence of image next to the list):

MWE render

Thanks for the help!

1 Answers1

1

The following builds upon https://tex.stackexchange.com/a/417571/117050 but extends it a lot. It defines the macros:

  • \InsertListR[<correction>]{<skip>}{<contents>} with the arguments <correction> being a correction factor as used by insbox (use it to extend the amount of lines affected), <skip> being a number of lines to skip before the insertion and <contents> being a box which is to be inserted.
  • \wrapitem used to start the first item after which you use \InsertListR
  • \contitem another item after you used \InsertListR which should also be affected. It takes an optional argument specifying the number of affected lines (defaulting to a whooping 100)
  • \EndInsert to manually stop the effects of an \InsertListR or any of the other insbox macros. It also starts a new paragraph. If the indentation should be suppressed you can use the starred version.

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{duckuments}% funnier than lipsum
\usepackage[margin=2cm]{geometry}
\usepackage{capt-of}
\usepackage{enumitem}

\input{insbox.tex}
\usepackage{etoolbox}
\newcommand*\wrapitem
  {%
    \apptocmd\labelitemi{\hskip\leftmargin}{}{}% add a correction
    \item
    \patchcmd\labelitemi{\hskip\leftmargin}{}{}{}% remove the added hskip
  }
\newsavebox\InsertListRbox
\newlength\InsertListPrevWidth
\makeatletter
\newcommand{\InsertListR}[3][]
  {%
    \mbox{}%
    \vspace*{-\baselineskip}%
    \setlength{\leftskip}{\leftmargin}%
    \setbox\InsertListRbox\hbox{#3}%
    \global\InsertListPrevWidth
      \dimexpr
        \wd\InsertListRbox+\@InsertBoxMargin
      \relax
    \InsertBoxR{#2}{\hskip-\leftmargin\box\InsertListRbox\hskip\leftmargin}[#1]%
  }%
\newcommand*\contitem[1][100]
  {%
    \item
      \ParShape=3
                {0}  0cm 0cm
                {#1} 0cm {\the\InsertListPrevWidth}
                1    0cm 0cm
  }
\newcommand*\EndInsert
  {
    \@restore@
    \@ifstar{\@afterindentfalse\@afterheading}{}%
  }
\makeatother

\begin{document}
\blindduck[1]
\begin{multicols}{0}
  \section{Introduction}
  \blindduck[-5]
  \begin{itemize}
    \wrapitem
    \InsertListR{0}
      {%
        \parbox{.48\columnwidth}
          {%
            \includegraphics[width=.48\columnwidth]{example-image-duck}%
            \captionof{figure}{foo}%
          }%
      }%
    one very very very very very long text
    \contitem two very very very very very long text
    \contitem three very very very very very long text
  \end{itemize}
  \EndInsert*
  \blindduck[1-5]
\end{multicols}
\end{document}

Results:

enter image description here

EDIT: More reasonable default for \contitem. By default this version does the same calculation insbox is doing to calculate the number of the affected lines. You can give the number explicitly if you're not satisfied with the results. It also changes the default value of \InsertListR to be a reasonable 0 (an empty default argument would be the same as 1, which won't be the expected behaviour from insbox).

Also for reasons I don't yet understand, the effect of \InsertListR is ended by the next new paragraph after the itemize environment. I therefore added a macro \MoreInsert which takes as its argument the number of lines which should be affected in the current paragraph (only in the current, another new paragraph ends its effect).

New code (in a complete MWE):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{duckuments}% funnier than lipsum
\usepackage[margin=2cm]{geometry}
\usepackage{capt-of}
\usepackage{enumitem}

\input{insbox.tex}
\usepackage{etoolbox}
\newcommand*\wrapitem
  {%
    \apptocmd\labelitemi{\hskip\leftmargin}{}{}% add a correction
    \item
    \patchcmd\labelitemi{\hskip\leftmargin}{}{}{}% remove the added hskip
  }
\newlength\InsertListPrevWidth
\makeatletter
\newcommand{\InsertListR}[3][0]
  {%
    \mbox{}%
    \vspace*{-\baselineskip}%
    \setlength{\leftskip}{\leftmargin}%
    \InsertBoxR{#2}{\hskip-\leftmargin#3\hskip\leftmargin}[#1]%
    \global\InsertListPrevWidth\@framewidth
  }%
\newcommand*\contitem[1][\the\count1]
  {%
    \item
    \bgroup  % to keep some changes local
      % let's calculate parameters for \ParShape
      \def\reserved@a{#1}%
      \def\reserved@b{\the\count1}%
      \ifx\reserved@a\reserved@b
        % Below calculation is copied from \@@InsertBox of insbox
        \dimen0 = \@wherebottom
        \advance \dimen0 by -\pagetotal
        \divide \dimen0 by \baselineskip
        \count1 = \dimen0
        \advance \count1 by 1
        \advance \count1 by -\@numnormal
      \fi
      \MoreInsert{#1}%
    \egroup
  }
\newcommand*\EndInsert
  {%
    \@restore@
    \@ifstar{\@afterindentfalse\@afterheading}{}%
  }
\newcommand*\MoreInsert[1]
  {%
    \ParShape = 2
                {#1}   0cm   {\the\InsertListPrevWidth}
                1      0cm   0cm
  }
\makeatother

\begin{document}
\blindduck[1]
\begin{multicols}{0}
  \section{Introduction}
  \blindduck[-5]
  \begin{itemize}
    \wrapitem
    \InsertListR{0}
      {%
        \parbox{.48\columnwidth}
          {%
            \includegraphics[width=.48\columnwidth]{example-image-duck}%
            \captionof{figure}{foo}%
          }%
      }%
    one very very very very very long text
    \contitem two very very very very very long text
    \contitem three very very very very very long text
  \end{itemize}

  \MoreInsert{1}
  \blindduck[1-5]

  \blindduck[1-5]
\end{multicols}
\end{document}
Skillmon
  • 60,462
  • That worked wonders, thank you very much! Quick add-on question, if I want to slightly increase the distance between the list on the left and the caption/figure, what should I change? – Rui Apóstolo Oct 03 '18 at 14:00
  • @RuiApóstolo include \makeatletter\@InsertBoxMargin=<length>\makeatother in your preamble after \input{insbox.tex}. Obviously <length> should be the width you want to use. Default of insbox is 2mm if I remember correctly. – Skillmon Oct 03 '18 at 15:37
  • Just to add (in case someone else needs it) the package \usepackage{caption} breaks this solution (especially the \MoreInsert command. I changed to \usepackage{capt-of} like @Skillmon has on their example and it works flawlessly. – Rui Apóstolo Oct 04 '18 at 15:41
  • @RuiApóstolo for me it works flawlessly with caption, generating identical output as with capt-of in my test cases. – Skillmon Oct 05 '18 at 07:28
  • Might have been my particular combination of packages then, I'm also using xcolor and contour on my figure captions. But as I said, with capt-of all works. – Rui Apóstolo Oct 05 '18 at 12:39
  • @RuiApóstolo can you please provide a minimal example where above commands fail? Without a document reproducing the issues I can't look into it, but it might be of great value for future visitors. – Skillmon Oct 05 '18 at 15:09
  • I feel like I might be missing something really basic here, and if so, apologies for wasting your time. You can find a MWE on overleaf (no account needed to open code) here. Image used can be found here. – Rui Apóstolo Oct 07 '18 at 00:03
  • @RuiApóstolo The reason why \MoreInsert isn't working in your code is because you start a new paragraph after using it (the empty line). As mentioned in my edit, it has to be used inside of the paragraph (put the empty line from below \MoreInsert above it). Also in this case you'd have to use the optional argument of \contitem because the default calculation fails (this is due to the additional spacing around the items in an itemize environment). – Skillmon Oct 07 '18 at 07:22
  • I'm very sorry, I completely missed that detail regarding the \MoreInsert command.

    I went back to my previous version of the poster, and it seems that had I use the optional argument of \contitem it would have been fine.

    If you don't mind me asking: why does \contitem fail on a 3 line paragraph when it defaults to 100, does it have to do with the combination of word lengths and column widths?

    – Rui Apóstolo Oct 08 '18 at 10:43
  • @RuiApóstolo if you use my second code block, it doesn't use the default of 100, but instead the calculation done by insbox and that one fails (I assume because of the different spacing in itemize environments, but am not completely sure atm). If time (and the original author) permits I'll try to write a package using a similar approach as insbox to solve the problem in LaTeX (which will then hopefully be list aware). I'm currently reading the sources of wrapfig and plan to read the sources of other packages resolving around text-floating as well. – Skillmon Oct 08 '18 at 11:27