I am having a hard time sometimes getting wrapfig to work and I don't know what the problem is. I stripped an example down to show you one such effect. In this example you will see ghost image placements in the paragraphs below the actual image. I can avoid them in this example by moving the wrapfig further down, the other way to fix it in this example is to delete the \hspace{16pt}. In the stripped down example it was easy to fix but in other cases in my actual document I found it almost impossible to sort out. My question is what tips do people have to avoid issues with wrapfig and what is the cause?






\hspace{16pt}  Draw an equilateral triangle.




Example behavior


1 Answer 1


If you use a latex older than 2020-04-21 you get

enter image description here

wrapfig documents that the paragraph containing the wrapping text should not start in a group that ends before the cutout finishes. Otherwise wrapfig "forgets" where it is and re-starts the cutout.

Your example is like

{x}  Draw an equilateral triangle.

with the paragraph starting at x inside the group. You can fix this with

\leavevmode {x}  Draw an equilateral triangle.

so the paragraph starts before the {.

In your case, that would be

\leavevmode\hspace{16pt}  Draw an equilateral triangle.

Which produces the required output.

It is somewhat weird to start a paragraph with \hspace but I suspect this should be considered a latex bug, especially as it worked until 2020.

To see what changed see ltspace.dtx which has the old and new versions:

% \begin{macro}{\@hspace}
% \changes{LaTeX2e}{1993/08/05}
%    {(RmS) Removed superfluous \cs{leavevmode} in \cs{@hspace} and
%               \cs{@hspacer}, as suggested by CAR.}
% \changes{v1.3m}{2020/04/21}{Support calc syntax (gh/152)}
%    \begin{macrocode}
%<latexrelease>                 {\@hspace}{Support calc with \hspace}%
%    \end{macrocode}
%    \begin{macrocode}
%<latexrelease>                 {\@hspace}{Support calc with \hspace}%

%<latexrelease>\def\@hspace#1{\hskip #1\relax}

A \begingroup group was added to support calc but we could probably adjust this.

  • If you (plural, meaning the team) just had never done that evil change in 1993 and removed the \leavevmode :)
    – Skillmon
    Nov 28, 2022 at 11:44
  • Thanks for the help. What would you recommend to use instead of \hspace{16pt} to indent a single line?
    – rhody
    Nov 28, 2022 at 17:10
  • @rhody \hspace* would be a bit more natural (and wrapfig would work:-) but really any use of hspace in document is suspicious. A font change such as \textbf{Aim:} followed by explicit spacing is the classic example of what latex's "logical markup" aims to avoid. It should be a list item or heading or custom command or something, with the layout implemented elsewhere. Of course using \myfoo{Aim} would make your document logically cleaner but wouldn't necessarily help fix your problem as this is basically a latex bug which we will fix.... So I'd just use \hspace* here... Nov 28, 2022 at 17:38
  • I thought of using a list but felt it was overkill for just one line.
    – rhody
    Nov 28, 2022 at 18:01
  • PS \hspace* works.
    – rhody
    Nov 28, 2022 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .