# wrapfig vs intextsep

This is a follow up to https://tex.stackexchange.com/a/266431/3929

Consider the MWE below. For now, ignore that we cannot provide arguments to \wrapfigure, what I'm trying to understand is this:

Why is it that if I set \intextsep globally to zero, then no extra vertical padding is added to the wrapped figure. But it is not enough to set it to zero inside it wrapper env. Ulrike has already answered by it does disappear in the very first one in the example. But try adding the section and the image will be shifted down.

Why?

\documentclass{article}

\usepackage{wrapfig}
\usepackage{kantlipsum}

\newcommand\fig{\rule{3cm}{15mm}}

%\setlength\intextsep{0pt}

\newenvironment{mw}{%
\setlength\intextsep{0pt}
\wrapfigure[4]{l}{3cm}
}{\endwrapfigure}

\begin{document}

%\section{Test}

\begin{mw}
\fig%
\end{mw}
\kant[1]

\begin{mw}
\fig%
\end{mw}
\kant[1]
\end{document}


The result of the MWE:

The result of adding a section

The result of globally setting \intextsep to zero

The documentation says

If you put a wrapfigure in a parbox or a minipage, or any other type of grouping, the text wrapping should end before the group does.

So if you put \wrapfig in your environment group you have to put your (Kant) text in there as well.

• Uhh, I missed that one. How annoying. Is there any alternatives? In my case the user wants to start every chapter with a small wrapped figure. I guess as long as everything is text at the start of the chapter we could just wrap the very first paragraph. – daleif Nov 13 '15 at 16:01
• An interesting observation: if in the mwe, you add \noindent right after the mw env, then the image disappears. – daleif Nov 13 '15 at 16:03
• @daleif If you put wrapfig in a group you are lucky to get any output:-) – David Carlisle Nov 13 '15 at 16:06
• @daleif can't you use a command rather than an environment to add the start of section figure? then it's much easier to control the grouping – David Carlisle Nov 13 '15 at 16:07
• @daleif but your group is making the settings of \parshape local so everything likely to go bad. If you want a local setting of \intextsep just do \skip0=\intextsep ..... \intextsep=\skip0 or an allocated register rather than skip0 to save the value. – David Carlisle Nov 13 '15 at 16:17

As you have a quite specific wrapfig and don't want to pass options you could insert a vspace inside the wrapfig:

\documentclass{article}

\usepackage{wrapfig}
\usepackage{kantlipsum}
\def\mw{\wrapfigure[4]{l}{3cm}\ifdim\pagetotal=0pt \else\vspace{-\intextsep}\fi}
\let\endmw\endwrapfigure
\newcommand\fig{\rule{3cm}{15mm}}

\begin{document}

%\section{Test}

\begin{mw}
\fig%
\end{mw}
\kant[1]

\begin{mw}
\fig%
\end{mw}
\kant[1]

\end{document}


• Usable, thanks. But this is of course just a simple mwe to show the problem. The real application should need all the options. In which case your solution could be mixed with the one I linked to at the beginning. Don't spend more time on it, David has already explained what the actual problem is – daleif Nov 13 '15 at 17:26
• I feel the need to comment on this. Adding a vspace to remove the intextsep is nice, but it does not work if the width of the wrapfigure is specified as 0pt (automatic). Somehow the vspace gets ignored in that case. So if a vspace is used, the width has to be set explicitly (for example with \widthof{}. – Sunday Jun 21 '16 at 15:46