This happens because wrapfig
doesn't handle page breaks and sectioning commands very well. Your figure exceeds the space left on the page. Plus there is some eerie interaction with the starred \section*
command. (You can check: if you use the unstarred version for section 'Introduction', this problem will go away). I don't know any elaborate hack to prevent this and the alternative, the (much older) floatflt
package doesn't handle this any better. In fact, manual adjustment is suggested in the documentation.
So I suggest you move the wrapfigure
environment one (or two) paragraphs up, if you need unnunmbered sections. If (it's rather likely) there is still bothersome whitespace below the figure (caption) you can remove it with a hack:
\begin{wrapfigure}{r}{0.5\textwidth}
\includegraphics[width=0.4\textwidth]{this.JPG}
\caption{Testing Apparatus}
\label{apparatus}
\vspace{-1.5cm}
\end{wrapfigure}
Modify the negative amount for \vspace
according to your needs.
This is governed by the \intextsep
length. You can set it to zero to avoid the empty space above and below the wrapfig
environment:
\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{lipsum}
\begin{document}
\setlength\intextsep{0pt}
\begin{wrapfigure}{l}{0.45\textwidth}
\includegraphics[width=0.45\textwidth]{pic}
\caption{Ligament case}
\end{wrapfigure}
\noindent\lipsum[1]
\end{document}
If you wish the change to stay local (which I would advise), you can wrap the \setlength
, the wrapfig
and the paragraph which is to be wrapped around the figure inside a group:
\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{lipsum}
\begin{document}
\lipsum[1-2]
{%
\setlength\intextsep{0pt}
\begin{wrapfigure}{l}{0.45\textwidth}
\includegraphics[width=0.45\textwidth]{pic}
\caption{Ligament case}
\end{wrapfigure}
\noindent\lipsum[1]%
}
\lipsum[2]
\end{document}
Lastly, you could also put a negative \vspace
inside the wrapfig
environment:
\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{wrapfigure}{l}{0.45\textwidth}
\vspace{-\baselineskip}
\includegraphics[width=0.45\textwidth]{pic}
\caption{Ligament case}
\end{wrapfigure}
\noindent\lipsum[1]
\lipsum[2]
\end{document}
The caveat of this solution is that if the wrapfig
is at the top of a new page, it will be shifted above the first line (so you need to remove the \vspace
command). Also, it requires you to manually determine the appropriate amount by which to shift manually (\baselineskip
is probably what you usually want though).
As a side note: I would generally not set \parindent
to zero globally, unless you really want it to be zero everywhere, but instead use a \noindent
before a paragraph which is not supposed to start with an indented line.
Edit:
Result for the second code snippet:
EDIT 2:
The reason why you'd almost certainly want your changes to \intextsep
to stay local is that it is a LaTeX length for governing float behavior, not something specific to wrapfig
. As per Lamport in LaTeX - A Document Preparation System:
\intextsep
The vertical space placed above and below a float that is
put in the middle of the text with the h
location option. It is a
rubber length.
(p.200, Section C.9.1)
EDIT 3:
In response to user's comment, here's the code which produces the desired result for me when doing this multiple times:
\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{lipsum}
\begin{document}
\lipsum[1-2]
{%
\setlength\intextsep{0pt}
\begin{wrapfigure}{l}{0.45\textwidth}
\includegraphics[width=0.45\textwidth]{pic}
\caption{Ligament case}
\end{wrapfigure}
\noindent\lipsum[1]%
}
\lipsum[2]
{%
\setlength\intextsep{0pt}
\begin{wrapfigure}{l}{0.45\textwidth}
\includegraphics[width=0.45\textwidth]{pic}
\caption{Ligament case}
\end{wrapfigure}
\noindent\lipsum[1]%
}
\end{document}
Best Answer
It seems if you have math following wrapfigure, it moves all text following it. If you add even a single line of text it solves the problem.