1

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?

  • 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
  • 1
    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

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.

|improve this answer|||||
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.