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?

naphaneal
  • 2,614
  • 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 '19 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 '19 at 13:40
  • @Teepeemm actually Martin provided the example-images not the graphix package (but yes they are useful:-) – David Carlisle Jun 15 '19 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 '19 at 13:41
  • @leandriis Look at that! Must have missed it sorry! – MartijnKor Jun 15 '19 at 13:54

1 Answers1

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.

David Carlisle
  • 757,742
  • Oke thank you! I – MartijnKor Jun 15 '19 at 13:42
  • @MartijnKor in a perfect world you wouldn't need that but.... – David Carlisle Jun 15 '19 at 13:43
  • 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? – Herb Schulz Jun 15 '19 at 14:52
  • @HerbSchulz preventing the figure floating to top of this page is something I wondered about mentioning (\suppressfloats[t]) but that will change the layout for the rest of the document so might be undesirable in a "final edit", moving the figure earlier in the source is an alternative to resetting the numbers I agree. – David Carlisle Jun 15 '19 at 14:59
  • 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. – Donald Arseneau Aug 27 '20 at 07: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. – Donald Arseneau Aug 27 '20 at 08:02
  • 2
    @DonaldArseneau can't we just blame the wrapfig author? – David Carlisle Aug 27 '20 at 08:18
  • How's that galley package coming? – Donald Arseneau Aug 27 '20 at 08:20