2

My document has a number of \hrulefill for a student to write about a picture which is inset using the wrapfig package.

However, the rules underneath the figure don't extend far enough-as if the figure keeps on extending downward: creative writing When I replace the rules with any text, the wrapfig works fine. It is just the \hrulefill that doesn't behave.

How do I fix it?

MWE:

\documentclass{article}
\usepackage{wrapfig}
\setlength{\parskip}{8ex}
\setlength{\unitlength}{1cm}
\begin{document} 
\hrulefill

\hrulefill

\begin{wrapfigure}{r}{0.5\textwidth}
  \begin{center}
    \framebox(5,5)[c]{some picture}
  \end{center}
\end{wrapfigure}
\hrulefill

\hrulefill

\hrulefill

\hrulefill

\hrulefill

\hrulefill

\hrulefill

\hrulefill
\end{document}
  • 2
    Wrapfig has a problem with anything which takes more space than \baselineskip per line of text. You can terminate the wrapping using \WFclear. – John Kormylo May 21 '18 at 18:40
6

Use the optional argument of wrapfig which sets the number of shortlines:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{wrapfig}
\setlength{\parskip}{8ex}
\setlength{\parindent}{0pt}
\setlength{\unitlength}{1cm}
\usepackage{lipsum}

\begin{document}

\hrulefill

\hrulefill

\begin{wrapfigure}[4]{r}{0.5\textwidth}
 \centering
    \framebox(5,5)[c]{some picture}
\end{wrapfigure}


\hrulefill

\hrulefill

\hrulefill

\hrulefill

\hrulefill

\hrulefill

\hrulefill

\hrulefill

\end{document} 

enter image description here

Edit : A more automatic solution can be obtained with the plain TeX macro package insbox. The \InsertBoxR command has to be inserted before a paragraph begins. It takes two mandatory arguments: the number of untouched lines before the object in the box is inserted, and the inserted object. As it may happen TeX gets a wrong box height, an optional argument can be use (at the end of the command, which is the number of supplementary shorter lines. Here is a demo with a real graphic file:

    \documentclass{article}
    \usepackage{geometry}
    \usepackage{graphicx}
    \parskip = 8ex
     \setlength{\parskip}{8ex}
     \setlength{\parindent}{0pt}
    \setlength{\unitlength}{1cm}
    \input{insbox.tex}

    \begin{document}

    \hrulefill

    \hrulefill

\vspace*{\parskip}
\InsertBoxR{0}{\parbox[t]{0.48\linewidth}{\centering
\includegraphics{pepe-le-pew2}}}%

   \hrulefill

    \hrulefill

    \hrulefill

    \hrulefill

    \hrulefill

    \hrulefill

    \hrulefill

    \hrulefill

    \end{document} 

enter image description here

  • Either this solution or the use of \WFclear (@John Kormylo) requires me to determine the height of the figure in terms of lines. Unfortunate this is not automatic, but at least for me that's not an issue. – Tim May 22 '18 at 13:57
  • 1
    @Tim: I've added another, more automatic solution. – Bernard May 22 '18 at 14:56

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.