# wrapfigure cuts off images at the end of the page

I used the code from here to get text to wrap around images, but whenever I have a long image near the end of the page, it runs off the page and gets cut off. How do I fix this?

-

When positioning the wrapped float, you can specify uppercase L or R for the position, instead of lowercase l, r. This allows the wrapfigure environment to float and LaTeX can move it to avoid page overflow.

-

\makeatletter
\newcommand{\checkheight}[1]{%
\par \penalty-100\begingroup%
\setbox8=\hbox{#1}%
\setlength{\dimen@}{\ht8}%
\ifdim \dimen@>\dimen@ii
\break
\fi\endgroup}
\makeatother

and then use

\checkheight{\includegraphics[..]{...}}
\begin{wrapfigure}...\end{wrapfigure}

to check whether the image will fit on the page or not. If it does/will fit, nothing will happen. If it does/will not fit, a break (page or column) is issued, so the next paragraph will start on a new page.

The above code was taken from the minimal needspace package.

-
I don't want to be tough, but it does mean that one has to include the graphics twice, first to check its siye and then to include it? –  yo' Jan 27 '12 at 19:13
@tohecz: That's correct. I'm not sure whether this requirement is an isolated instance, and therefore a separate commands seems viable. If not, and this check has to be included with each, it would be possible to include such a check as part of the wrapfigure environment. –  Werner Jan 27 '12 at 19:15