# Wrapfigures beneath section headings misbehave

I'm writing a chemistry thesis and my experimental basically consists of section headings (naming the compound), followed immediately by a wrapfigure (an eps of the compound structure), followed by the experimental procedure and characterisation data (which wrap around the structure). However, if there isn't enough space between where the wrapfigure is called and the end of the page:

(a) if the figure is floating, it is pushed onto the next page, beside the next paragraph which is invariably a new compound, so it overlaps with the structure that is supposed to be there,

(b) if the figure is non-floating, it hangs below the lower margin on that page and pointless whitespace is created on the next page where the image is hypothetically "hanging."

\documentclass{book}

\usepackage{color,graphicx}
\usepackage{float}
\usepackage{wrapfig}

\title{Thesis}
\author{}

\begin{document}

\chapter{Experimental}

In our previous papers, we reported the palladium-catalyzed cross-coupling reaction of stuff. The compounds are readily accessible by hydroboration of alkenes and alkynes, the stereochemistry of 1-alkenyl groups both on boron and halides are completely retained in the products, many functional groups including ester, ketone, and aldehyde are tolerated, and high turnovers of the palladium catalysts are observed.

In our previous papers, we reported the palladium-catalyzed cross-coupling reaction of stuff. The compounds are readily accessible by hydroboration of alkenes and alkynes, the stereochemistry of 1-alkenyl groups both on boron and halides are completely retained in the products, many functional groups including ester, ketone, and aldehyde are tolerated, and high turnovers of the palladium catalysts are observed.

In our previous papers, we reported the palladium-catalyzed cross-coupling reaction of stuff. The compounds are readily accessible by hydroboration of alkenes and alkynes, the stereochemistry of 1-alkenyl groups both on boron and halides are completely retained in the products, many functional groups including ester, ketone, and aldehyde are tolerated, and high turnovers of the palladium catalysts are observed.

In our previous papers, we reported the palladium-catalyzed cross-coupling reaction of stuff. The compounds are readily accessible by hydroboration of alkenes and alkynes, the stereochemistry of 1-alkenyl groups both on boron and halides are completely retained in the products, many functional groups including ester, ketone, and aldehyde are tolerated, and high turnovers of the palladium catalysts are observed.

\subsection{Toluenesulfonic acid 2-azidoethyl ester}

\begin{wrapfigure}{L}{0.18\textwidth}
\includegraphics[scale=0.65]{img.eps}
\end{wrapfigure}

In our previous papers, we reported the palladium-catalyzed cross-coupling reaction of stuff. The compounds are readily accessible by hydroboration of alkenes and alkynes, the stereochemistry of 1-alkenyl groups both on boron and halides are completely retained in the products, many functional groups including ester, ketone, and aldehyde are tolerated, and high turnovers of the palladium catalysts are observed.  In our previous papers, we reported the palladium-catalyzed cross-coupling reaction of stuff. The compounds are readily accessible by hydroboration of alkenes and alkynes, the stereochemistry of 1-alkenyl groups both on boron and halides are completely retained in the products, many functional groups including ester, ketone, and aldehyde are tolerated, and high turnovers of the palladium catalysts are observed.

\subsection{Toluenesulfonic acid 2-azidoethyl ester}

\begin{wrapfigure}{L}{0.18\textwidth}
\includegraphics[scale=0.65]{img.eps}
\end{wrapfigure}

In our previous papers, we reported the palladium-catalyzed cross-coupling reaction of stuff. The compounds are readily accessible by hydroboration of alkenes and alkynes, the stereochemistry of 1-alkenyl groups both on boron and halides are completely retained in the products, many functional groups including ester, ketone, and aldehyde are tolerated, and high turnovers of the palladium catalysts are observed.  In our previous papers, we reported the palladium-catalyzed cross-coupling reaction of stuff. The compounds are readily accessible by hydroboration of alkenes and alkynes, the stereochemistry of 1-alkenyl groups both on boron and halides are completely retained in the products, many functional groups including ester, ketone, and aldehyde are tolerated, and high turnovers of the palladium catalysts are observed.

\end{document}


I don't know how to add img.eps on here... but I assume anything would work. To see the non-floating case the optional argument [L] is changed to [l].

-
I should comment that I can only see two ways this might be fixed: (1) some way of making the floating wrapfigure start immediately on the next page (which is somewhat better than waiting for the next paragraph which always causes an image clash) or (2) some way of forcing a bad page break prior to offending section headings (is there a way to automate this?) – bsd Jun 13 '11 at 18:48

You could use the nobottomtitles option from the titlesec package. Add to the preamble:
\usepackage[nobottomtitles*]{titlesec}

With this option, titles close to the bottom margin will be moved to the next page. You can control the minimal space required in the bottom margin not to move the title using \renewcommand{\bottomtitlespace}{<length>} (default value is .2\textheight.)