Wrong vertical spacing cutwin (clean solution text wrap image)

I noticed package cutwin seems to have issues with linespacing (see above image). After searching, several others also noticed this: Linespacing with cutwin, Misalignment with cutwin, http://tug.org/mail-archives/texhax/2011-September/018163.html

In https://tex.stackexchange.com/a/133691 it is remarked that packages wrapfig, picins, cutwin, etc. do not always work well with vertical spacing.

I chose for cutwin as an often opted solution to manually position images and wrap text around them. Particularly in/near lists, since wrapfig often fails here. I am slightly annoyed I devoted time and energy in learning cutwin only to see that this package has its own issues. So my questions are:
(1) Can cutwin's erroneous vertical spacing be fixed?
(2) If the answer to (1) is no, does the solution of https://tex.stackexchange.com/a/59106/120150, using cutwin and parshape, handle vertical spacing well?
(3) If the answer to (2) is no, what is the cleanest solution to wrap text around an image? (image does not need to float) I have seen several solutions come by but not yet a consensus about what is best. See for example https://tex.stackexchange.com/a/208436, Will it ever be possible to use wrapfig with an enumerate or itemize environment?, https://www.abhilashnair.com/troubleshooting/how-to-use-wrapfig-wrapfigure-in-an-enumerated-or-list-environment-in-latex/, https://tex.stackexchange.com/a/232110

MWE:

\documentclass[11pt, a4paper]{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}

\usepackage{mwe}
\usepackage{cutwin}

\begin{document}
\section*{Test}
\lipsum[2]

\renewcommand*{\windowpagestuff}{%
\centering\bfseries
Text \\ in \\ Window \par}

\opencutright
\begin{cutout}{2}{0.5\textwidth}{0pt}{7}
\lipsum[1]
\end{cutout}

\lipsum[2]
\end{document}


There's a plain TeX macro package which isn't often mentioned: insbox and does a good job. For your case, we can use the \InsertBoxR command just before a paragraph; it takes two mandatory arguments: the number of lines with normal length at the beginning of the paragraph, and what you want to insert. It can take an optional argument (contrary to LaTeX usage, it's the last argument): the number of supplementary shorter lines, in case TeX computes erroneously the necessary number of shorter lines.

Likewise there exists a \InsertBoxL command.

\documentclass[11pt, a4paper]{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[latin]{babel}

\usepackage{mwe}
\input{insbox}

\begin{document}
\section*{Test}

\lipsum[2]

\InsertBoxR{2}{\parbox[b][6\baselineskip][c]{0.48\textwidth}{\bfseries\centering Text \\ in \\ Window }}
\lipsum[1]

\lipsum[2]

\end{document}


Edit: To add a caption for a figure or a table, as it is no more a float, you have to use \captionof, defined in the caption package. The whole stuff has to be included in a \parbox or a minipage. Here is an example:

\documentclass[11pt, a4paper]{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[latin]{babel}
\usepackage{graphicx, caption}

\usepackage{mwe}
\input{insbox}

\begin{document}

\section*{Test}

\lipsum[2]

\InsertBoxR{2}{\parbox[b][6\baselineskip][t]{0.48\textwidth}{\centering\includegraphics[scale=0.75]{pepe-le-pew2}
\captionsetup{labelfont = bf, format= hang}\captionof{figure}{Pepe Le Pew in full action}}}[5]
\lipsum[1]

\lipsum[2]

\end{document}


• I also wish to apply it to (non-floating) figures in/near lists. Your solution for that at tex.stackexchange.com/a/417571/120150 and Skillmon's improvement at tex.stackexchange.com/a/453624/120150 are not really the clean solution I was hoping for. – Bart Apr 24 '19 at 14:12
• I've added an example code for that. You have to put everything in a \parbox or a minipage. – Bernard Apr 24 '19 at 14:47
• What were you hoping for? – Bernard Apr 24 '19 at 14:48
• I indeed got your solution working with an image in a parbox. And this solution is still rather clean. But when I looked at the code in order to get it working near/in a list, I became less happy. – Bart Apr 24 '19 at 15:06
• I've just taken a look at the code you mention. Since then, I've improved iit, using enumitem. May be you should post a new question (with a full code, of course!) – Bernard Apr 24 '19 at 15:13

I'll post my solution with insbox combined with lists. Credits go to Bernard for contriving the solution.

As you can see, the last paragraph is not handled well in this case. Also having an item containing both text of regular width and text that needs to wrap around a box is not so easy with InsertBox. You need to do a lot of manual interventions, leading to lengthy code. Insbox last optional parameter is also not entirely clear to me, it seems to introduce extra vertical spacing, seemingly in lines. Conclusion: Insbox does the job for simple cases, the adjustbox package seems more powerful and mature if you want to go beyond the simple cases. I say 'seems', because I haven't tested this package. My 2 cents: Latex would be better off with one decent solution(/package) for text wrapping around boxes instead of the plethora of non-optimal solutions that currently exists. And to forget about floating, even the wrapfig documentation does not recommend enabling its floating functionality.

\documentclass[11pt, a4paper]{article}

\usepackage{calc}

\usepackage{lmodern}
\usepackage[T1]{fontenc}

\usepackage[draft]{graphicx}

\usepackage{enumitem}

\input{insbox}

\usepackage{mwe}

\begin{document}
\section*{Test}
\InsertBoxR{2}{\parbox[b][2\baselineskip][t]{4cm}{
\includegraphics[width=4cm]{image.png}
}}
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi.
Morbi auctor lorem non justo. Nam lacus libero, pretium at, lobortis
vitae, ultricies et, tellus. Donec aliquet, tortor sed accumsan biben-
dum, erat ligula aliquet magna, vitae ornare odio metus a mi.
\newlength{\origTopsep}
\begin{enumerate}[rightmargin=4.2cm]
\setlength{\origTopsep}{\topsep}
\item \lipsum[2]
\setlength{\topsep}{0pt}
\end{enumerate}
\begin{enumerate}[resume]
\setlength{\topsep}{\origTopsep}
\item \lipsum[2]
\item \lipsum[2]
\end{enumerate}
\lipsum[2]
\end{document}
`