Too much space around wrap figure

75,879

Solution 1

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.

Solution 2

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:
75,879
Jeel Shah
Author by

Jeel Shah

Updated on April 30, 2020

Comments

  • Jeel Shah
    Jeel Shah over 3 years

    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?

    • Razor
      Razor over 10 years
      Does the image have white-space to it's left side ? Or is the image just that window screenshot ?
    • Jeel Shah
      Jeel Shah over 10 years
      @Razor No, there is no whitespace around the image. The image just the window.
    • Razor
      Razor over 10 years
      I had a similar problem and fixed it using \begin{wrapfigure}{r}{*insert number here* \textwidth}
  • Say OL
    Say OL about 7 years
    Can we decrease more horizontal space between text and figure?
  • Royi
    Royi over 6 years
    Is there a way to set the Margins around \caption{Basic layout} to be minimal?
  • user0
    user0 over 5 years
  • Augustin
    Augustin over 3 years
    You can use \includegraphics[width=\linewidth]{Program_Layout.png}. If you then want to change the width of the figure, you have to change it only in a single place.
  • David Carlisle
    David Carlisle over 1 year
    with more recent lipsum you need to add a paragraph break before the \endgroup see tex.stackexchange.com/q/635953/1090