[Tex/LaTex] Strange behaviour of wrapfigure if followed by equation

equationswrapfigure

I have just had some problem with wrapfigure where I used the following code:

\documentclass[a4paper, 12pt]{article} 

\usepackage{wrapfig} % to have text around figures
\usepackage{graphicx}   
\usepackage{amsmath}

\begin{document}
\subsubsection*{Sample Subsection}
\begin{wrapfigure}{r}{0.25\textwidth}
    \includegraphics[width=0.23\textwidth]{sampleFigure}
    \caption{Heat Balance for the ceiling node}
\end{wrapfigure}
\begin{equation*}
    a^2+b^2=c^2
\end{equation*}
with 
\begin{align*}
    a^2+b^2&=c^2 & a^2+b^2&=c^2 \\
    a^2+b^2&=c^2 & a^2+b^2&=c^2 \\
    a^2+b^2&=c^2 & a^2+b^2&=c^2
\end{align*}
can be solved to
\begin{equation}
   a^2+b^2=c^2
\end{equation}

\subsubsection*{Sample Subsection}
\begin{wrapfigure}{r}{0.25\textwidth}
    \includegraphics[width=0.23\textwidth]{sampleFigure}
    \caption{Heat Balance for the ceiling node}
\end{wrapfigure}
-> With some text it is working!
\begin{equation*}
    a^2+b^2=c^2
\end{equation*}
with 
\begin{align*}
    a^2+b^2&=c^2 & a^2+b^2&=c^2 \\
    a^2+b^2&=c^2 & a^2+b^2&=c^2 \\
    a^2+b^2&=c^2 & a^2+b^2&=c^2
\end{align*}
can be solved to
\begin{equation}
   a^2+b^2=c^2
\end{equation}

\end{document}

In the first subsection there is a problem, whereas the second subsection looks as I expected. The only difference between the two sections is the line starting with "->".

Does anyone have an explanation for this behaviour?

Best Answer

I can't profess to understand the internals of what brought on the problem to begin with; however, placing a \leavevmode after the \end{wrapfigure} resolves the issue.

I inferred the answer from the observed behavior that adding some text after the wrapfigure also resolves the issue. One thing that adding text does is take you out of vertical mode, so I tried leaving vertical mode as a solution, and it worked. Is that a bug with wrapfig? I couldn't say.

(For the rest of the readers, commenting that one line will re-create the problem.)

\documentclass[a4paper, 12pt]{article} 

\usepackage{wrapfig} % to have text around figures
\usepackage[demo]{graphicx}   
\usepackage{amsmath}

\begin{document}
\subsubsection*{Sample Subsection}
\begin{wrapfigure}{r}{0.25\textwidth}
    \includegraphics[width=0.23\textwidth]{sampleFigure}
    \caption{Heat Balance for the ceiling node}
\end{wrapfigure}
\leavevmode% THIS RESOLVED IT
\begin{equation*}
    a^2+b^2=c^2
\end{equation*}
with 
\begin{align*}
    a^2+b^2&=c^2 & a^2+b^2&=c^2 \\
    a^2+b^2&=c^2 & a^2+b^2&=c^2 \\
    a^2+b^2&=c^2 & a^2+b^2&=c^2
\end{align*}
can be solved to
\begin{equation}
   a^2+b^2=c^2
\end{equation}

\subsubsection*{Sample Subsection}
\begin{wrapfigure}{r}{0.25\textwidth}
    \includegraphics[width=0.23\textwidth]{sampleFigure}
    \caption{Heat Balance for the ceiling node}
\end{wrapfigure}
-> With some text it is working!
\begin{equation*}
    a^2+b^2=c^2
\end{equation*}
with 
\begin{align*}
    a^2+b^2&=c^2 & a^2+b^2&=c^2 \\
    a^2+b^2&=c^2 & a^2+b^2&=c^2 \\
    a^2+b^2&=c^2 & a^2+b^2&=c^2
\end{align*}
can be solved to
\begin{equation}
   a^2+b^2=c^2
\end{equation}

\end{document}

enter image description here

Related Question