1

I have a twosided document and want to add some wrapfigures. The specialty is that I want wrapped section titles on left pages.

The example shows the problem for the second section. For the first and third everything is fine.

MWE:

    \documentclass[12pt,a4paper,twoside,openright]{scrbook}

    \usepackage{wrapfig}
    \usepackage{graphicx}
    \usepackage{caption}
    \usepackage[english]{babel}
    \usepackage{blindtext}

    \begin{document}
        \chapter{First Chapter}
        \section{First Section}
        \begin{wrapfigure}[14]{o}{0.4\linewidth}
            \begin{center}
                \includegraphics[width=0.75\linewidth]{picture}
            \end{center}
            \vspace*{-1em}
            \captionsetup{width=0.75\linewidth}
            \caption[short]{long.}
        \end{wrapfigure}

        \blindtext[5]


        \section{Second Section}
        \begin{wrapfigure}[14]{o}{0.4\linewidth}
            \begin{center}
                \includegraphics[width=0.75\linewidth]{picture}
            \end{center}
            \vspace*{-1em}
            \captionsetup{width=0.75\linewidth}
            \caption[short]{long.}
        \end{wrapfigure}

        \blindtext

        \section{Third Section}
        \begin{wrapfigure}[14]{o}{0.4\linewidth}
            \begin{center}
                \includegraphics[width=0.75\linewidth]{picture}
            \end{center}
            \vspace*{-1em}
            \captionsetup{width=0.75\linewidth}
            \caption[short]{long.}
        \end{wrapfigure}

        \blindtext

    \end{document}

Result:

enter image description here

  • actually the third section title is on wrong place. this is caused because the text in this section is to short for correct warping for image (it has 13 lines, but you reserved for wrapping 14 lines; this confuse wraping). if you would extend this text, for example with \blindtext[2], then all section titles will appear on the left side of the text as they should be. – Zarko Mar 23 '18 at 10:05
  • Yes, this is true and intended. I like it better when the title is above the text and not above the image. Another possible solution would be to make two columns, one for the images and one for the text. Is it possible to place images on the inner column? – Daniel Mar 23 '18 at 10:12
  • this is with wrapfigure impossible to achieve. you should find another way (if exist). – Zarko Mar 23 '18 at 10:17
2

what you like to obtain is not possible to do only with wrapfigure. as solution can be enclosed sections' titles into \parbox:

enter image description here

\documentclass[12pt,a4paper,twoside,openright]{scrbook}

\usepackage{wrapfig}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage[english]{babel}
\usepackage{blindtext}

\usepackage{refcount}
\newcounter{secalign}
\newcommand{\secmove}{
    \refstepcounter{secalign}
    \label{secmove-\thesecalign}
    \mbox{}\par\noindent%
    \ifodd\getpagerefnumber{secmove-\thesecalign}
        \parbox{#1}{#2}
    \else
        \hfill\parbox{#1}{#2}
    \fi}

\begin{document}
    \chapter{First Chapter}
    \secmove{0.58\linewidth}{\section{First Section}}
    \begin{wrapfigure}[11]{o}{0.4\linewidth}
        \centering
            \includegraphics[width=0.75\linewidth]{picture}
        \captionsetup{skip=0.5ex, width=0.75\linewidth}
        \caption[short]{long.}
    \end{wrapfigure}
    \blindtext[5]

    \secmove{0.58\linewidth}{\section{Second Section}}
    \begin{wrapfigure}[11]{o}{0.4\linewidth}
        \centering
            \includegraphics[width=0.75\linewidth]{picture}
         \captionsetup{skip=0.5ex, width=0.75\linewidth}
        \caption[short]{long.}
    \end{wrapfigure}
    \blindtext

    \secmove{0.58\linewidth}{\section{Third Section}}
    \begin{wrapfigure}[11]{o}{0.4\linewidth}
        \centering
            \includegraphics[width=0.75\linewidth]{picture}
        \captionsetup{skip=0.5ex, width=0.75\linewidth}
        \caption[short]{long.}
    \end{wrapfigure}
    \blindtext[2]
\end{document}

solution in above code is aware, on which page (odd or even) the sections' titles are, however it need to be compiled at least twice.

note: what you claim that section position is work correct actually happens by accident as consequence of wrong wrapfigure settings (you declare to it use more line numbers as text beside of figure has),

beside this i made the following (off-topic) changes to your code:

  • to \captionsetup ad option skip=0.5ex and the remove all \vspace*{-1em} in wrapfigure
  • replace \begin{centering} with \centering and with this remove additional vertical space abobe and below image
  • erase \end{centering}
  • remove empty line between wrapfigure and \blindtext (or real text). this is important since with enclosing sections in parbox it lost capability to remove parindent in the following text.
  • I use sometimes \wrapfigure. This answer is very important for me. +1 (upvote). – Sebastiano Mar 23 '18 at 11:43
  • @Sebastiano, thank you very much! wrapfigure is very capricious environment :-) what op claim that work correctly actually happens by accident ... as consequence of wrong wrapfigure settings .... – Zarko Mar 23 '18 at 12:17
  • With such sincerity I realized that wrapfigure is very capricious environment. In this period I am writing a physics book together with a university professor in memory of my beloved dad. At the end of the work, which is still almost half-finished, I will try to at least improve the appearance of the text, which I hope will be published, appropriately placing the images. You will always have my upvotes :-) – Sebastiano Mar 23 '18 at 21:48

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.