[Tex/LaTex] Handling of wrapfig pictures in LaTeX

wrapfigure

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} 

Best Answer

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

Related Question