Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer

You could add the following to your document preamble:

\makeatletter
\newcommand{\checkheight}[1]{%
  \par \penalty-100\begingroup%
  \setbox8=\hbox{#1}%
  \setlength{\dimen@}{\ht8}%
  \dimen@ii\pagegoal \advance\dimen@ii-\pagetotal
  \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.

share|improve this answer
1  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.