6

The text is slightly higher than the image when initially starting the sentence. I have tried using vspace or \ to lower the sentence. But it just moves the whole image down with the text. Is there some simple fix like a package i'am missing. If i were to start the wrapfig on a new page the problem is gone though.

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{subfig}
\numberwithin{figure}{section}
\usepackage{wrapfig}
\usepackage{refstyle}
\graphicspath{{F}}
\usepackage{pdfcolparallel}
\usepackage{booktabs}
\usepackage{array}
\usepackage{pdflscape}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{multirow}
\setlength{\parindent}{0pt}
\begin{document}



 \clearpage
\subsubsection{Stepped Nozzle}
bla blah blah

\begin{wrapfigure}{L}{0.45\textwidth}
\centering
\captionsetup{justification=centering}
    \includegraphics[scale=.6]{liggy}
    \caption{Ligament case}
\end{wrapfigure}

In figure 4.16, the stepped nozzle has produced a vast amount of ligaments on the bottom angle. 
\end{document}

Example of problem

gernot
  • 49,614
user
  • 115

1 Answers1

16

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:

code result

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}
alpenwasser
  • 2,455
  • Okay first of all thank you very much for solving my question so quickly. I tried adding another wrap fig below in order to show another example, so I copied the same code but line reappeared for the second wrap fig. I tried setting the \intextsep command again but I don't see any changes? – user Apr 20 '17 at 22:25
  • Okay just tried the \vspace{-\baselineskip} twice and its solved thankssss – user Apr 20 '17 at 22:30
  • @user In the second wrapfig, did you set \intextsep to zero also the second time (you need to set it to zero for each wrapfig if you put it inside {...})? Because it works for me if I do it like that. Specifically, if you're using the second code example, you need to copy everything from {% \setlength\intextsep{0pt ... wrapfig ... \noindent\lipsum[1]} (or whichever text you have instead of \lipsum, of course). I'm glad that the other way works for you though. – alpenwasser Apr 20 '17 at 22:41
  • @user I have added a code example with two wrapfigs which works for me. – alpenwasser Apr 20 '17 at 22:48
  • When I replace my \lipsum with my own text, the images get pushed to the left, nearly outside the document? – user Apr 20 '17 at 23:05
  • @user Hard to say what's causing that without a compilable example, I haven't really been able to break mine. If the figure gets pushed into the margin, you could try adding a negative overhang parameter: \begin{wrapfigure}{l}[-5mm]{0.45\textwidth}. Also, make sure the width parameters both of the wrapfigure and the \includegraphics are sensible. The scale option didn't really work for me, which is why I changed it to width=0.45\textwidth. Otherwise, you'll probably need to paste the code you're currently trying to compile. – alpenwasser Apr 20 '17 at 23:33
  • Is there any way to set \intextsep to zero globally but only for wrapfigure? Because putting every wrapfigure into {...} doesn't work, if I'm not having pure text around the wrapfigures all the time. As I use a lot of lists, that happens quite frequently and the \vspace{-\baselineskip} solution seems so unelegant to me. – Druid Raves - V Feb 15 '18 at 02:43
  • @EmeraJade You could maybe try to have a look at the code of wrapfigure itself and create your own wrapfigure environment which takes this into account based on that code. – alpenwasser Feb 16 '18 at 12:05
  • 1
    @alpenwasser That has already been done, however it didn't solve the issue :( I summarised all related questions in my own question https://tex.stackexchange.com/questions/415398/adjust-intextsep-for-wrapfigure-only – Druid Raves - V Feb 16 '18 at 12:28