# Prevent wrapfigure from wrapping the next section

Code:

\documentclass{article}
\usepackage[a5paper]{geometry}
\usepackage{wrapfig}
\usepackage{lipsum}
\begin{document}
\begin{wrapfigure}{l}{0.5\textwidth}
\rule{4cm}{12cm}
\end{wrapfigure}
\lipsum[1]

\section{Hello}

Hello section text
\end{document}


Prints:

1. How can I make it shift \section{Hello} to the left?
2. And more generally: never wrap any text in the new section, following wrapfigure?
• I don't know of an automated solution for this; you can use the first optional argument to manually restrict the number of narrow lines: \begin{wrapfigure}[29]{l}{0.5\textwidth}...\end{wrapfigure} and, in your concrete case, reduce the skip for the caption: \usepackage{caption} and then something like \captionsetup[wrapfigure]{skip=3pt} \begin{wrapfigure}[29]{l}{0.5\textwidth} \rule{4cm}{12cm} \caption{some text} \end{wrapfigure} – Gonzalo Medina Jun 24 '13 at 23:21

With the text and image as they are, wrapfig needs a bit of help.

You could tell it to stop wrapping after 29 lines:

\begin{wrapfigure}[29]{l}{0.5\textwidth}


But the result is rather squeezed:

A much better result in this case is to simply add \clearpage before the \section and move it to the next page.

• Hehe! I was writing the same thing in my comment. I also suggested there a possible workaround for the caption skip. – Gonzalo Medina Jun 24 '13 at 23:22

You could simply include the wrapfig and the wrapped text in brackets as follows:

{
\begin{wrapfigure}{l}{0.5\textwidth}
\rule{4cm}{12cm}
\end{wrapfigure}
\lipsum[1]
}
\section{Hello}


This stops the wrapping at the line where the wrapped text stops. As pointed out by Andrew Swann, this doesn't work if the figure is longer than the text; in that case, the following section heading will be overwritten by the figure.

• Welcome to Tex.SX! Unfortunately that does not entirely work, the wrapping stops but the section heading gets overridden by the figure. Perhaps you can improve the answer, and also make it into a complete compilable document, rather than just a code snippet. – Andrew Swann Sep 4 '14 at 9:51
• Didn't work for me. Even if I included the last paragraph that should wrap in the curly brackets, it didn't wrap, and got overwritten by the figure. – Jeffrey Lebowski Mar 23 '16 at 14:54
• This sent the image at the end of the doc – axolotl Aug 23 '16 at 14:32

If the text wrapping the figure ends in some actual text and not just included text like \lipsum, then it works to just add empty lines to the end of the text.

\documentclass{article}
\usepackage[a5paper]{geometry}
\usepackage{wrapfig}
\usepackage{lipsum}
\begin{document}
\begin{wrapfigure}{l}{0.5\textwidth}
\rule{4cm}{11cm}
\end{wrapfigure}
\lipsum[2]
text\\ \\ \\ \\ \\ \\ \\ \\

\section{Hello}

Hello section text
\end{document}