# Too much space around wrap figure

I am using the wrapfig package to have my text around the figure but there is too much space around it as you can see below.

Here is the code that I am using, I looked at the wikibook on LaTeX for this issue and it suggested that I use \vspace{-xpt} to decrease the amount but it's not working very well. Here is the code for wrapfig.

\begin{wrapfigure}{r}{0.5\textwidth}
\vspace{-20pt}
\centering
\includegraphics[scale=0.5]{Program_Layout.png}
\vspace{-10pt}
\caption{Basic layout}
\end{wrapfigure}


How can I fix the code such so the text can get as close as possible?

-
Does the image have white-space to it's left side ? Or is the image just that window screenshot ? –  Razor Apr 29 '13 at 17:28
@Razor No, there is no whitespace around the image. The image just the window. –  gekkostate Apr 29 '13 at 17:29
I had a similar problem and fixed it using \begin{wrapfigure}{r}{*insert number here* \textwidth} –  Razor Apr 29 '13 at 17:30

Instead of using the scale option for \includegraphics, you could use width and select the same width that was declared for the wrapfigure environment:

\documentclass[10pt,a4paper]{article}
\usepackage[demo]{graphicx}
\usepackage{wrapfig}
\usepackage{lipsum}

\begin{document}

\begin{wrapfigure}{r}{0.5\textwidth}
\centering
\includegraphics[width=0.5\textwidth]{Program_Layout.png}
\vspace{-10pt}
\caption{Basic layout}
\end{wrapfigure}
\lipsum[1]

\end{document}


Using the first optional argument, then you can even suggest the appropriate number of lines:

\documentclass[10pt,a4paper]{article}
\usepackage[demo]{graphicx}
\usepackage{wrapfig}
\usepackage{lipsum}

\begin{document}

\begin{wrapfigure}[11]{r}{0.5\textwidth}
\centering
\includegraphics[width=0.5\textwidth]{Program_Layout.png}
\vspace{-10pt}
\caption{Basic layout}
\end{wrapfigure}
\lipsum[1]

\end{document}


The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

-

The spacing around the wrapfigure is given by two lengths: \columnsep (for horizontal padding) and \intextsep (for vertical padding). Here's an example illustrating the difference between the default and setting them all to 0pt:

\documentclass{article}
\usepackage{graphicx,lipsum,wrapfig}% http://ctan.org/pkg/{graphicx,lipsum,wrapfig}
\begin{document}
% Default settings
\begin{wrapfigure}{r}{0.5\textwidth}
\centering\includegraphics[width=\linewidth]{example-image-a}
\caption{Basic layout}
\end{wrapfigure}
\lipsum[1]

\begingroup
\setlength{\intextsep}{0pt}%
\setlength{\columnsep}{0pt}%
\begin{wrapfigure}{r}{0.5\textwidth}
\centering\includegraphics[width=\linewidth]{example-image-a}
\caption{Basic layout}
\end{wrapfigure}
\lipsum[1]
\endgroup
\end{document}


The default for \columnsep is 10pt, while \intextsep is 12.0pt plus 2.0pt minus 2.0pt. The following is taken from the wrapfig documentation (section 2 Sizing and optional overhang, p 3):

LaTeX will wrap surrounding text around the ﬁgure, leaving a gap of \intextsep at the top and bottom, and \columsep at the side, by producing a series of shortened text lines beside the ﬁgure. The indentation (shortening) of the text is the ﬁgure width plus \columnsep minus overhang (if any; see below).

LaTeX calculates the number of short lines needed based on the height of the ﬁgure and the length \intextsep. You can override this guess by giving the ﬁrst optional argument (parameter #1) specifying the number of shortened lines (counting each displayed equation as 3 lines). This is particularly useful when the surrounding text contains extra vertical spacing that is not accounted for automatically.

So, barring that you don't have any whitespace around your actual image, you can also adjust \columnsep and \intextsep to your liking for any particular wrapfigure.

-