Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

example of too much space

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?

share|improve this question
    
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

2 Answers 2

up vote 7 down vote accepted

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}

enter image description here

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}

enter image description here

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

share|improve this answer

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:

enter image description here

\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]

% Adjusted settings
\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 figure, 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 figure. The indentation (shortening) of the text is the figure width plus \columnsep minus overhang (if any; see below).

LaTeX calculates the number of short lines needed based on the height of the figure and the length \intextsep. You can override this guess by giving the first 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.