2

This is a follow up of Typesetting errors with two wrapfigures on one page?.

Consider the case here:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{wrapfig}

\def\a{One two three four five six. }
\def\b{\a\a Red green blue yellow white black. }
\def\c{\b\b\a\b\b\b\a\b\b}

\begin{document}

\begin{wrapfigure}{r}{0.4\textwidth}
\centering
    \includegraphics[width=0.38\textwidth]{none}
  \caption{Figure with little text}
  \label{hausdorffShapes}
\end{wrapfigure}
\b

\begin{wrapfigure}{l}{0.4\textwidth}
\centering
    \includegraphics[width=0.38\textwidth]{none}
  \caption{Another figure here}
  \label{hausdorffBadExample}
\end{wrapfigure}
\b\b\c

\end{document}

which is quite a common case when I write a solution to an exercise of electronics --- quite a lot of schematics and sometime just a little of text on the side. Unfortunately, with the due warning, I have this output:

Misplaced text at the side

I can fix it like this (adding the [3] and the \vspace{} manually, by visually editing at the end).

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{wrapfig}

\def\a{One two three four five six. }
\def\b{\a\a Red green blue yellow white black. }
\def\c{\b\b\a\b\b\b\a\b\b}

\begin{document}

\begin{wrapfigure}[3]{r}{0.4\textwidth}
\centering
    \includegraphics[width=0.38\textwidth]{none}
  \caption{Figure with little text}
  \label{hausdorffShapes}
\end{wrapfigure}
\b

\vspace{4cm}

\begin{wrapfigure}{l}{0.4\textwidth}
\centering
    \includegraphics[width=0.38\textwidth]{none}
  \caption{Another figure here}
  \label{hausdorffBadExample}
\end{wrapfigure}
\b\b\c

\end{document}

which led to the correct (at least, in this case; I admit is not so nice) document:

figure ok, lot of space, but hey...

Is it possible to do this automatically? I mean, a \clearwrapfigure command that emits the necessary vertical space and restart the normal paragraph shape?

1 Answer 1

4

Something like this seems to work, you may prefer it with \mbox{} rather than \mbox{zz} but this shows what it is doing.

enter image description here

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{wrapfig}

\def\a{One two three four five six. }
\def\b{\a\a Red green blue yellow white black. }
\def\c{\b\b\a\b\b\b\a\b\b}

\makeatletter
\def\clearwf{\par{\count@\c@WF@wrappedlines\zz}\par}

\def\zz{{%
\ifnum\count@>\@ne
\noindent\mbox{zz}\\%
\advance\count@\m@ne
\expandafter\zz
\else
\ifhmode\unskip\unpenalty\fi
\fi}}

\makeatother

\begin{document}

\begin{wrapfigure}{r}{0.4\textwidth}
\centering
    \includegraphics[width=0.38\textwidth]{none}
  \caption{Figure with little text}
  \label{hausdorffShapes}
\end{wrapfigure}
\b


\clearwf

\begin{wrapfigure}{l}{0.4\textwidth}
\centering
    \includegraphics[width=0.38\textwidth]{none}
  \caption{Another figure here}
  \label{hausdorffBadExample}
\end{wrapfigure}
\b\b\c

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .