4

I need to insert images wrapped in text. wrapfig obviously comes to mind. The problem is the wrapped figure, by default, ignores margins and even page ends.

I mean, if I put the image less than its height from the page end, the image trespasses margins and even page dimensions, getting cut out, instead of going in the next page like graphicx does.

Here's an example:

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{wrapfig}

\begin{document}

Text at the top

\vspace{17cm}

\begin{wrapfigure}{r}{9cm}
\includegraphics[width=9cm]{zappa}
\end{wrapfigure} 

\lipsum[5]

\end{document}

Which, looking where the first page ends and the second begins, results in this

Image cut out

As you can see, the image goes beyond the lower margin, where the text ends, gets cut out where the page ends.

Also, the rest of the text, which gets in the next page as the first is finished, presents the shape of the part of the image which wasn't counted in the indentation of text in page 1.

This forces me to manually adjust the block by putting, for example, a newpage before \begin{wrapfigure}. If I latter change something above it, I may have to manually change my adjustment maybe by removing the newpage and so on.

Is there a way to make wrapfig automatically adjust the layout, like graphicx does when it has the [H] option?

  • 1
    perhaps you want R rather than r ? (also not important for the question but [H] is from the float package not graphicx) – David Carlisle Feb 5 '16 at 11:20
  • That indeed solves perfectly my problem. Thanks a lot! I feel a little stupid for not immediately thinking about putting the capital letter to force orientation. Sorry about H mistake as well, forgot I had to include float to use it. – Jeffrey Lebowski Feb 5 '16 at 11:40
  • Also, I ask this in a comment not thinking it deserves a standalone question, but correct me if I'm wrong. don't like how the first line (Vestibu-) goes a little off, and how some lines (like Mac-, Nulla and Morbi) do that too, even if by less characters. Is there a way to wrap the lines perfectly? – Jeffrey Lebowski Feb 5 '16 at 11:43
  • 1
    That presumably gave an overfull hbox warning: you need to tell tex how to hyphenate the word, tex has a hard job hyphenating pseudo-latin especially as here you are using the hyphenation tables for english. – David Carlisle Feb 5 '16 at 11:54
  • You are right again. Changing lipsum with blindtext softened the problem (a few lines were still a little incoherent and some overfull hbox warnings still stood), but reducing image width to a realistic one in an article finally solved it: I guess that where lines are too short some problem can still occur. Well, thanks for everything! – Jeffrey Lebowski Feb 5 '16 at 16:09
9

You can use R rather than r and then wrapfig will allow the figure to float to a certain extent to avoid falling off the end of a page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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