4

MWE:

\documentclass[a4paper]{article}
\usepackage{mwe}
\usepackage{wrapfig}
\usepackage{blindtext}

\begin{document}

\blindtext \blindtext \blindtext \blindtext 

\begin{wrapfigure}{l}{0.5\textwidth}
\centering
\includegraphics[height=150pt,width=0.5\textwidth]{example-image-a}
\caption{A caption}
\end{wrapfigure}

\blindtext 

\end{document}

PICTURE

Undesidered space on new page

I want wrapfig do detect new page and start the text from the left margin of the page. Instead, the margin is such like the figure was still there

I would prefer an automated solution, as not to manually specify the number of narrow lines using the optional argument of wrapfig. I frequently change the text before the wrapfig.

2

Use package needspace and then:

\documentclass[a4paper]{article}
\usepackage{mwe}
\usepackage{wrapfig}
\usepackage{blindtext}
\usepackage{needspace}

\begin{document}

\blindtext \blindtext \blindtext \blindtext 

\Needspace{150pt}%% Same as image height 
\begin{wrapfigure}{l}{0.5\textwidth}
\centering
\includegraphics[height=150pt,width=0.5\textwidth]{example-image-a}
\caption{A caption}
\end{wrapfigure}
\blindtext 

\end{document}

I used only the image height for \needspace. In reality it should include the caption height.

enter image description here

1
  • 1
    I didn't know that package. Thanks! For completeness, needspace inserts a pagebreak if there is not enough space – raffaem Jan 22 '16 at 11:18
1

Just for fun:

\documentclass[a4paper]{article}
\usepackage{mwe}
\usepackage{caption}
\usepackage{blindtext}

\begin{document}

\blindtext \blindtext \blindtext \blindtext 

\noindent\rlap{\raisebox{-\height}[0pt][0pt]{\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[height=150pt,width=\textwidth]{example-image-a}
\captionof{figure}{A caption}
\end{minipage}}}

\hangindent=\dimexpr 0.5\textwidth+\marginparsep\relax
\hangafter=-8
\blindtext 

\end{document}

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.