# wrapfigure misplaced

I have this code:

\chapter{Experimenteller Teil}
\begin{wrapfigure}{l}{0.2\linewidth}
%\centering
\includegraphics{image.pdf}
\end{wrapfigure}
\blindtext


and I get this:

as you can see, the picture is misplaced, but if I use multiple wrapfigure, all of them are placed at the right position, if I end the previous line (\\), except the last, which is placed on the margin again. I tried actual text instead of blindtext but same result.

I used scrreprt as document class.

EDIT: Minimal not-working example:

\documentclass
[
12pt,
a4paper,
twoside,
openany
]{scrreprt}
\usepackage{blindtext}
\usepackage{float}
\usepackage{graphicx}
\usepackage{wrapfig}

\begin{document}
\chapter{Chapter}
{
\blindtext \\
\begin{wrapfigure}{o}{0.2\linewidth}
%\centering
\includegraphics{image.pdf}
\end{wrapfigure}
\blindtext
\blindtext
\blindtext \\

\begin{wrapfigure}{o}{0.2\linewidth}
%\centering
\includegraphics{image.pdf}
\end{wrapfigure}
\blindtext
\blindtext
\blindtext \\
}
\end{document}

• I do not know why it causes this, but if you remove the blank line after blindtext \ the code behaves differently, and the image moves in the text – BambOo Aug 5 '18 at 16:49

Multiple remarks here.

I personally never used \blindtext so I replaced it with lipsum calls instead, and I removed the multiple \\ which don't seem appropriate (personal opinion here !).

So that anybody can compile your document I would adivse using example-image-a to obtain an example image, which is provided by the graphicx package (see the code below).

Finally, to address your question, if you add [width=\linewidth] to you includegraphics calls, the size of the image is derived from the width of the wrapfigure which avoids trespassing the margins or the text.

Working code

\documentclass
[
12pt,
a4paper,
twoside,
openany
]{scrreprt}
\usepackage{blindtext}
\usepackage{float}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{lipsum}

\begin{document}
\chapter{Chapter}

\lipsum[1]
\begin{wrapfigure}{o}{0.5\linewidth}
%\centering
\includegraphics[width=\linewidth]{example-image-a.pdf}
\end{wrapfigure}
\lipsum[1]
\lipsum[1]
\lipsum[1]

\begin{wrapfigure}{o}{0.5\linewidth}
%\centering
\includegraphics[width=\linewidth]{example-image-b.pdf}
\end{wrapfigure}
\lipsum[1]
\lipsum[1]
\lipsum[1]

\end{document}


Result

• well, you could use i.stack.imgur.com/AF2mN.png – sivizius Aug 5 '18 at 16:38
• Not sure I understand you comment... Does my answer address your problem ? – BambOo Aug 5 '18 at 16:40
• I misunderstood that you asked for an image. Anyway, this seems not to help. this example works, but not if I used it in my actual code. I try to figure it out and answer again later. – sivizius Aug 5 '18 at 16:44
• thanks for your effort, but this was not the solution. Bu I found a solution, but do not understand it, see below. – sivizius Aug 5 '18 at 16:56

For whatever reason, [width=\linewidth] was not the solution. I fixed it now by adding a empty line after the chapter:

\documentclass
[
12pt,
a4paper,
twoside,
openany
]{scrreprt}
\usepackage{blindtext}
\usepackage{float}
\usepackage{graphicx}
\usepackage{wrapfig}

\begin{document}
\chapter{Chapter}
{
\blindtext \\
\begin{wrapfigure}{o}{0.2\linewidth}
%\centering
\includegraphics{image.pdf}
\end{wrapfigure}
\blindtext
\blindtext
\blindtext \\

\begin{wrapfigure}{o}{0.2\linewidth}
%\centering
\includegraphics{image.pdf}
\end{wrapfigure}
\blindtext
\blindtext
\blindtext \\

%↑ this empty line was necessary to fix it, could someone explain?
}
\end{document}

• If you remove the brackets { ... } around your chapter, it behaves the same with or without the additionnal line ... – BambOo Aug 5 '18 at 17:00
• ok, I see, but why? – sivizius Aug 5 '18 at 17:10
• The thing is that I do not think that using \ inside the corpse of the document is a good practice... If someone else can back me up on this, feel free to do so. – BambOo Aug 5 '18 at 17:17
• never use \\  at the end of the paragraph (latex would have warned abount this: underfull box of 10000 (maximum) badness. – David Carlisle Aug 5 '18 at 22:32
• please use example-image as your test image (and adjust the dummy text to ensure that the problem occurs with that image, otherwise no one else can see the issue. the wrapfig documentaion does warn that there are restrictions of you use it in a group, which explains why you need a blank line if you have a group there but why do you have the chapter text in a group? – David Carlisle Aug 6 '18 at 8:24