1

How to make a long vertical image (using wrapfig) span over two questions from exsheet package? The following code does not produce a satisfactory result.

\documentclass{book}

\usepackage{lipsum}
\usepackage{wrapfig}
\usepackage[demo]{graphicx}
\usepackage{exsheets}

\begin{document}

\begin{wrapfigure}{r}{0.25\textwidth}
    \includegraphics[width=3cm,height=8cm]{}
\end{wrapfigure}

\begin{question} \lipsum[1] \end{question}

\begin{question} \lipsum[2] \end{question}

\begin{question} \lipsum[3] \end{question}

\end{document}

The problem is that all the subsequent questions have an odd blank space until I use \clearpage.

mwe

UPDATE I found one solution which is not perfect. If onу takes wrapfigure together with the first two questions in \parbox{}, other questions are not affected. But still there is too much of white vertical space in the second Exercise. It can be adjusted specifying number of "narrow lines" in wrapfigure like so: \begin{wrapfigure}[19]{r}{0.25\textwidth}. But I am still looking for a fully automated solution.

1
  • My results are nothing like yours. I've even tried XeLaTeX and LuaLaTeX. I get error messages from exsheets even without wrapfig. Jun 13, 2019 at 21:30

1 Answer 1

1

Here is the best alternative I can think of. I normally use \wrapspacer to do equations and such, but cannot break up the question environment. \wrapskip simply fills the remaining space that would be wrapped, if it could be wrapped.

\documentclass{book}

\usepackage{wrapfig}
\usepackage{graphicx}
\usepackage{exsheets}
\usepackage{lipsum}

\newcommand{\wrapspacer}[1]% #1 = special text
{\ifhmode\par\fi\leavevmode\bgroup
  \sbox0{\begin{minipage}{\linewidth}\hrule height0pt
    #1\hrule height0pt
    \end{minipage}}%
  \dimen0=\dimexpr \ht0+\dp0\relax
  \loop\ifdim\dimen0>\baselineskip
    \strut\vspace{-\baselineskip}\newline
    \advance\dimen0 by -\baselineskip
  \repeat
  \noindent\usebox0
  \hrule height0pt
\egroup}

\makeatletter
\def\wrapskip{\ifnum\c@WF@wrappedlines>2
  \advance\c@WF@wrappedlines by -2
  \vspace{\c@WF@wrappedlines\baselineskip}%
  \par\WFclear
\fi}
\makeatother

\begin{document}

\begin{wrapfigure}{r}{0.25\textwidth}
    \includegraphics[width=3cm,height=8cm]{example-image}
\end{wrapfigure}

\wrapspacer{\begin{question} \lipsum[1] \end{question}}

\wrapskip

\begin{question} \lipsum[2] \end{question}

\begin{question} \lipsum[3] \end{question}

\end{document}

You must log in to answer this question.

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