0

wrapfig is typically used with an intention to typeset it side by side with a certain text that should wrap it. However, when I use a lot of floats near wrapfig, a part of all of the text will not stay close to the wrapped figure. Also, the figure is not in order with the rest of others. How do I solve this?

enter image description here

My MWE

\documentclass[a4paper,12pt]{article}

\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{blindtext}
\usepackage[showframe]{geometry}
\usepackage{ragged2e}


\begin{document}

    \newcommand{\commonfigwidth}{0.35\linewidth}

    \begin{figure}
        \centering
        \includegraphics[width=\commonfigwidth]{example-image-a}
        \caption{My Fig}
    \end{figure}


    \begin{figure}
        \centering
        \includegraphics[width=\commonfigwidth]{example-image-b}
        \caption{My Fig}
    \end{figure}

    \begin{figure}
        \centering
        \includegraphics[width=\commonfigwidth]{example-image-c}
        \caption{My Fig}
    \end{figure}

    \begin{wrapfigure}{O}{\commonfigwidth} 
        \includegraphics[width=\linewidth]{example-image-a}
        \centering This is a circuit
    \end{wrapfigure}
    \blindtext

    \begin{figure}
        \centering
        \includegraphics[width=\commonfigwidth]{example-image-b}
        \caption{My Fig}
    \end{figure}

    \begin{figure}
        \centering
        \includegraphics[width=\commonfigwidth]{example-image-c}
        \caption{My Fig}
    \end{figure}

\end{document}
2

wrapfigure has no connection to the usual float mechanism so if you use both, you need to manage any issues that arise, here I think you get an acceptable output if you prevent the cutout carrying on the the next page, via

    \begin{wrapfigure}[8]{O}{\commonfigwidth} 
    \includegraphics[width=\linewidth]{example-image-a}
    \centering This is a circuit
    \end{wrapfigure}

so restricting it to 8 lines (instead of the 10 that it would use by default)

enter image description here

  • Thanks for the answer, but it is sometimes very necessary to guarantee that certain paragraph(s), even when they are long, stay very close to certain figures they describe (this is why many people want to use it instead of letting the figure float). I am not an expert, but I posted the question + answer because I wanted to share my experience working with this issue. – Al-Motasem Aldaoudeyeh Mar 1 at 14:59
  • @Al-MotasemAldaoudeyeh I hadn't seen you had posted an answer, to be honest I don't think it's an answer, as you have converted the main text from being part of the main document flow to an extended caption to the figure, of course using \blindtext it sort of looks OK either way but in practice I think it would be rather rare for a paragraph to be usable in either context. – David Carlisle Mar 1 at 15:07
0

enter image description here

LaTeX will not think of wrapfigure as a float unless it is written inside figure environment. All what exists inside figure or table environment must be shown at once on any page that LaTeX selects for. Thus, a good workaround is

\begin{figure}

    \begin{wrapfigure}{<other wrapfig arguments>} 
        \includegraphics[width=\linewidth]{<image file name>}
    \end{wrapfigure}

  <the text that should wrap the figure>

\end{figure}

That way, the paragraph(s) that are supposed to be near the wrapped figure will be forced to stay there even if the material around it has a lot of floats. Also, LaTeX will place all floats in the order they have appeared in the source code so this also solves the order issue mentioned.

\documentclass[a4paper,12pt]{article}

\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{blindtext}
\usepackage[showframe]{geometry}
\usepackage{ragged2e}


\begin{document}

    \newcommand{\commonfigwidth}{0.35\linewidth}

    \begin{figure}
        \centering
        \includegraphics[width=\commonfigwidth]{example-image-a}
        \caption{My Fig}
    \end{figure}


    \begin{figure}
        \centering
        \includegraphics[width=\commonfigwidth]{example-image-b}
        \caption{My Fig}
    \end{figure}

    \begin{figure}
        \centering
        \includegraphics[width=\commonfigwidth]{example-image-c}
        \caption{My Fig}
    \end{figure}

    \begin{figure}

        \begin{wrapfigure}{O}{\commonfigwidth} 
            \includegraphics[width=\linewidth]{example-image-a}
            \centering This is a circuit
        \end{wrapfigure}

    \blindtext

    \end{figure}

    \begin{figure}
        \centering
        \includegraphics[width=\commonfigwidth]{example-image-b}
        \caption{My Fig}
    \end{figure}

    \begin{figure}
        \centering
        \includegraphics[width=\commonfigwidth]{example-image-c}
        \caption{My Fig}
    \end{figure}

\end{document}
  • this moves the text to be out of order with the other text on the page so is only usable if the text is essentially an extended caption for the figure, it is not usable if the text is part of the main document flow. – David Carlisle Mar 1 at 15:08

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.