2

In Adjust intextsep for wrapfigure only, @Peter Grill provided an option to modify \intextsep for wrapfigure only and leave figure unaffected.

However it does not really work for me: as soon as a wrapfigure happens in the document, subsequent figure are affected too, so the setting obviously “leaks” into the environment. I have asked about this in comments to his answer, and he asked me to open a new question about my issue with a MWE, so here we are.

Here is a MWE showing the issue:

\documentclass{article}

\usepackage{graphicx}

\usepackage{wrapfig} \BeforeBeginEnvironment{wrapfigure}{\setlength{\intextsep}{0pt}}

\begin{document}

Some text initially.

\begin{figure}[hbt] \centering \includegraphics[width=.5\linewidth]{example-image-a} \caption{Notice how it is properly spaced above and below.} \end{figure}

Now let’s add some wrapped figure.

\begin{wrapfigure}{r}{.3\linewidth} \includegraphics[width=\linewidth]{example-image-a} \end{wrapfigure}

Asperiores est aspernatur dolorum sit. Expedita dolorum voluptatem iste. Eum laudantium ipsum ea omnis aut fugiat harum quis. Ut repellendus est incidunt. Esse cum a omnis. Explicabo odio inventore asperiores ex ad. Quidem quia voluptatibus incidunt. Est dolores est perferendis dicta ullam inventore. Deleniti ab enim accusantium sint qui voluptatem. Qui sed assumenda adipisci ad reiciendis velit magnam. Nobis aut nihil quae est. Molestiae possimus quo quia magnam et dicta odio. Est quia quasi rem vel omnis eveniet. Quasi rerum tempore velit consequatur consequatur consectetur veritatis. Sed blanditiis et sed libero consequatur sed. Numquam et ipsam rem. Sed facere aut ipsam. Tenetur rerum et sed est aspernatur ipsa quia. Hic error ut maiores doloremque quas. Error eum quae rerum modi debitis.

And now, a figure again.

\begin{figure}[hbt] \centering \includegraphics[width=.5\linewidth]{example-image-a} \caption{Notice how it is \emph{not} properly spaced above and below.} \end{figure}

See the issue ?

\end{document}

And the produced result: MWE output

Archange
  • 1,368

1 Answers1

3

well BeforeBeginEnvironment (now the env/wrapfigure/before hook) doesn't work as it is before the group created by wrapfig and so affects following figure environments.

Using the env/wrapfigure/begin hook with

\AddToHook{env/wrapfigure/begin}{\setlength{\intextsep}{0pt}}

doesn't work either as it resets \intextsep to early and this confuses the placement of the wrapfigure:

enter image description here

Resetting the value in the env/wrapfigure/after doesn't work either.

You could try to reset it before the next figure but on the whole I think one need to patch internal of wrapfigure here:

\documentclass{article}

\usepackage{graphicx}

\usepackage{wrapfig} \usepackage{etoolbox} \makeatletter \patchcmd\WF@putfigmaybe{\lower\intextsep}{}{}{\fail}% \AddToHook{env/wrapfigure/begin}{\setlength{\intextsep}{0pt}} \makeatother \begin{document}

Some text initially.

\begin{figure}[hbt] \centering \includegraphics[width=.5\linewidth]{example-image-a} \caption{Notice how it is properly spaced above and below.} \end{figure}

Now let’s add some wrapped figure.

\begin{wrapfigure}{r}{.3\linewidth} \includegraphics[width=\linewidth]{example-image-a} \end{wrapfigure}

Asperiores est aspernatur dolorum sit. Expedita dolorum voluptatem iste. Eum laudantium ipsum ea omnis aut fugiat harum quis. Ut repellendus est incidunt. Esse cum a omnis. Explicabo odio inventore asperiores ex ad. Quidem quia voluptatibus incidunt. Est dolores est perferendis dicta ullam inventore. Deleniti ab enim accusantium sint qui voluptatem. Qui sed assumenda adipisci ad reiciendis velit magnam. Nobis aut nihil quae est. Molestiae possimus quo quia magnam et dicta odio. Est quia quasi rem vel omnis eveniet. Quasi rerum tempore velit consequatur consequatur consectetur veritatis. Sed blanditiis et sed libero consequatur sed. Numquam et ipsam rem. Sed facere aut ipsam. Tenetur rerum et sed est aspernatur ipsa quia. Hic error ut maiores doloremque quas. Error eum quae rerum modi debitis.

And now, a figure again.

\begin{figure}[hbt] \centering \includegraphics[width=.5\linewidth]{example-image-a} \caption{Notice how it is \emph{not} properly spaced above and below.} \end{figure}

See the issue ?

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Awesome, thank you. Though, could you explain what the patch command does? I’m not familiar with that one. – Archange Apr 10 '23 at 19:10
  • @JohnKormylo lthooks has nothing regarding patchcmd, but I’ve found great explanations here https://tex.stackexchange.com/a/152811/56823. – Archange Apr 13 '23 at 15:20
  • Oops, that would be etoolbox, and the real question is the source for \WF@putfigmaybe (from wrapfig). – John Kormylo Apr 13 '23 at 19:46