5

I was passing some documents I had in HTML to LaTeX for a better printout. (Same project as my previous question.) The documents use usual HTML/CSS floating images (sometimes the images are inside a floating div including a caption.)

I would like to keep the behavior, so I am using the wrapfig package, however I have noticed that floats do not flow nicely through page breaks, footnotes (and presumptly other footers) etc.

The complete sample is stored in Github. However I include here a short version:

\documentclass[10pt]{article}
\usepackage{graphicx,wrapfig}
\newlength{\px}%
\setlength{\px}{0.26mm}
\begin{document}
\section{Lorem ipsum \& rose}
\begin{wrapfigure}{l}{300\px}\centering
\includegraphics[width=300\px,height=197\px]{rose300.jpg}
\caption{Lorem ipsum dolor sit amet}
\end{wrapfigure}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.\footnote{%
from \emph{http://lipsum.net}} Mauris in tortor eu risus convallis
pharetra. Suspendisse potenti. Ut malesuada sed lorem molestie volutpat.
Vivamus volutpat eu tortor non tempor.
\begin{wrapfigure}{r}{240\px}\centering
\includegraphics[width=240\px,height=158\px]{rose240.jpg}
\caption{Aenean feugiat justo nisi}
\end{wrapfigure}
Aenean feugiat justo nisi, eget blandit ligula tristique non. Nam non
lectus est. Curabitur vel scelerisque urna. Sed auctor molestie leo ac
luctus. Quisque ornare tellus tortor, vel convallis purus elementum id.
Vestibulum lectus nibh, ultrices placerat aliquam vel, accumsan ut elit.
\end{document}

The longer version will produce the following output:

apage 1bpage 2

Note that the third figure is outside the bottom margin overlapping the footnote and the text in the beginning of the second page is reserving space for the image that is not there.

The project has over 167 different documents (posts), currently compiling over 609 pages, and with 168 images (currently 40 of them inside a wrapfigure environment, but this number might get higher when I complete my conversion script). Manual tuning is not an option for now.

So: How can I get the figures to flow nicely between pages preserving as much as possible the original format of the post?

  • 1
    You can make a shorter sample source with: \lipsum[1-150]. \usepackage{lipsum} is necessary for it. Thanks to Patrick Happel – user2987828 Nov 29 '13 at 16:28
  • 1
    And you can replace \includegraphics[width=300\px,height=197\px]{rose300.jpg} by \hrule width 300pt height 197pt depth 0mm – user2987828 Nov 29 '13 at 16:48
  • There are alternatives to lorem ipsum. – user2987828 Nov 29 '13 at 16:53
1

This is not easy in LaTeX as discussed in first point of this answer.

Make a first compilation in which each figure had its outer box modified so that its surface is unchanged but its width is \textwidth.

From the .log file, record the page on which each figure is, and the location of page breaks inside the flow of sentences.

Then, at each pagebreak, freely position all figures of the page in the same \begin{picture}(0,0)(0,0) environment anchored at the first word. And use \parshape just after \end{picture}, with the list of margins of every text line.

| improve this answer | |

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.