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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an way to avoid this behavior of the pictures

enter image description here

This is have is wrap the picture:

\begin{wrapfigure}{r}{0.5\textwidth} 
\vspace{-20pt}
  \begin{center}
    \includegraphics[width=0.4\textwidth]{./pictures/DBuserTabel.png}%{./Pictures/mainscreen1.png}
    \caption{Uklip af User tablen i Databasen}
    \label{fig:databaseUserTable}
  \end{center}
  \vspace{-20pt}
  \vspace{1pt}
\end{wrapfigure} 
share|improve this question
    
I have the same issue. But combining the methods explained by Avi Ginsburg and Gonzalo Medina and the use of the new line command \\ before the wrapfigure environment solved my problem. – Arnaud Triay-Alcouffe Mar 13 at 19:45
up vote 48 down vote accepted

The behaviour you describe is caused by using the wrapfig environment too close to a page break, as the following example demonstrates:

\documentclass{article}
\usepackage{wrapfig}
\usepackage{lipsum}

\begin{document}

\lipsum[1-4]
\begin{wrapfigure}{r}{5cm}
\centering
\rule{3cm}{7cm}
\end{wrapfigure}
\lipsum[1-6]

\end{document}

enter image description here

The wrapfig package documentation explicitly warns about this:

The environment should be placed so as to not run over a page break

so, you need to move your wrapfig environment to guarantee that it won't run over a page break. However, using R (or L) instead of r (or l) your figure will float, so simply changing r to R in the above code, as in

\documentclass{article}
\usepackage{wrapfig}
\usepackage{lipsum}

\begin{document}

\lipsum[1-4]
\begin{wrapfigure}{R}{5cm}
\centering
\rule{3cm}{7cm}
\end{wrapfigure}
\lipsum[1-6]

\end{document}

now yields:

enter image description here

share|improve this answer
    
Okay. So LaTeX doesn't have any automation, that does this automatically. So the solution if i understand you correct, is to do it manually replace the pictures? – mortenstarck May 17 '12 at 2:28
    
@mortenstarck:in this concrete case (wrapfig package), if the environment runs over a page break, I am afraid that you will have to manually move the environment; of course, those changes must be best done when working on the final version of the document. – Gonzalo Medina May 17 '12 at 2:33
2  
Is there another way of doing it, there it does page break in consideration. Because it's an quit big repport, with quit afew pictures? – mortenstarck May 17 '12 at 2:38
    
@mortenstarck: there are other packages around for wrapping text around elements (cuwin, for example), but I've never used them, so I don't know if they can automatically handle page breaks. Perhaps you should start a fresh new question about this new issue. (Don't forget to revisit this question a little later and accept the answer that best solved the concrte issu of this question). – Gonzalo Medina May 17 '12 at 2:45
2  
@mortenstarck I've updated my answer giving a simple solution to your problem. – Gonzalo Medina May 21 '12 at 0:39

The accepted answer offers one method (make the figure float). If all you need is to remove the white box on the subsequent page, you can just add negative spacing. Adapting Gonzalo Medina's example:

\documentclass{article}
\usepackage{wrapfig}
\usepackage{lipsum}

\begin{document}

\lipsum[1-4]
\begin{wrapfigure}{r}{5cm}
  \centering
  \rule{3cm}{7cm}
  \vspace{-110pt} % This removes the white box on the second page
\end{wrapfigure}
\lipsum[1-6]

\end{document}

Alternatively, you can count the number of rows on the first page the wrapfigure occupies and insert that number in the first optional parameter of the wrapfigure:

\documentclass{article}
\usepackage{wrapfig}
\usepackage{lipsum}

\begin{document}

\lipsum[1-4]
\begin{wrapfigure}[10]{r}{5cm}
%                  ^^ This dictates the number
%                   of text rows the wrapfigure
%                   will occupy.
  \centering
  \rule{3cm}{7cm}
  \vspace{-110pt}
\end{wrapfigure}
\lipsum[1-6]

\end{document}

Both of these methods result in the following output:

enter image description here

share|improve this answer
1  
I'm not sure that this would usually be the output people are looking for.... – jon Mar 26 at 5:02
    
@jon Agreed, but in a less exaggerated form it might be useful to someone out there. It is a big world... – Avi Ginsburg Mar 26 at 18:10

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.