[Tex/LaTex] Too much space around wrap figure

floatsspacingwrapfigure

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?

Best Answer

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.

Related Question