2

I am having an issue with wrapfigure and I can't seem to find a solution anywhere. Not even in the documentation. What happens is as follows: I have a wrapfigure environment in my code followed by a standard figure environment. The standard figure is placed on top, but gets a figure number higher than the wrapped figure. This is my code:

\documentclass{article}

\usepackage{lipsum}
\usepackage{wrapfig}
\usepackage{graphicx}

\begin{document}
    \begin{wrapfigure}{r}{3cm}
    \includegraphics[width=\linewidth]{C:/Users/<username>/Desktop/1.jpg}
    \caption{Picture of a dog.}
    \end{wrapfigure}
    \lipsum[1-2]
    \begin{figure}
        \centering
        \includegraphics[width=.7\linewidth]{C:/Users/<username>/Desktop/2.jpg}
        \caption{Another picture of a dog.}
    \end{figure}
\end{document}

And this is my output:

enter image description here

Does any of you perhaps know the solution?

5
  • Welcome to TeX.SE. If nothing else, you can manually adjust the figure counter. But I'll bet there's another way. (Unrelated, but graphicx provides the images example-image-a (and b and c) so that your minimal working example (which is very helpful) can be fully self-contained.)
    – Teepeemm
    Jun 15, 2019 at 13:38
  • Ow that is good to know about the example images! I know you can indeed manually set the figure numbers, but I hope to refrain from doing so.
    – MartijnKor
    Jun 15, 2019 at 13:40
  • @Teepeemm actually Martin provided the example-images not the graphix package (but yes they are useful:-) Jun 15, 2019 at 13:41
  • 2
    From the manual: "The wrapfigure and wraptable environments interact properly with the \caption command to produce proper numbering, but they are not regular floats like figure and table, so (beware!) they may be printed out of sequence with the regular floats."
    – leandriis
    Jun 15, 2019 at 13:41
  • @leandriis Look at that! Must have missed it sorry!
    – MartijnKor
    Jun 15, 2019 at 13:54

1 Answer 1

1

that is expected as wrapfigure is a non floating environment so floating figures can float past it.

If it is still that way in the final document version after all other edits done, you can fix as follows:

put

\addtocounter{figure}{1}

in the wrapfig before the caption and

\addtocounter{figure}{-2}

in the figure just before the caption.

8
  • Oke thank you! I
    – MartijnKor
    Jun 15, 2019 at 13:42
  • 1
    It looks like the figures are numbered properly but the float is going to the top of the page. Why not simply place the float above the wrapfigure paragraph or force it off the top of the page? Jun 15, 2019 at 14:52
  • 1
    ...and \addtocounter{figure}{1} after the regular figure caption. (But yuck.) I usually recommend flafter.sty which tends to fix this problem (and has such an erudite author). People who are upset about figures floating above a wrapfig are usually worried about figures coming before their text reference also. Aug 27, 2020 at 7:42
  • 1
    ... but with flafter, or [b] figure placement, you tend to get lower numbered figures coming after a higher numbered wrapfig. Maybe try placeins.sty and \FloatBarrier right before \begin{wrapfigure}. That will have its own unsightly risks. A wrapfigure should not be forced to float far, and multiple wrapfigures cannot be queued. Aug 27, 2020 at 8:02
  • 2
    @DonaldArseneau can't we just blame the wrapfig author? Aug 27, 2020 at 8:18

You must log in to answer this question.

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