0
\documentclass{article}
\usepackage{tikz-cd,wrapfig}
\begin{document}
\noindent
\begin{wrapfigure}[4]{r}{0pt}
    \includegraphics[width=2cm]{test.png}
\end{wrapfigure}
2. test test test test test test test test test test test test test\\
3. test test test test test test test test test test test test test test test test test test test test\\
4. test test test test test test test test test test test test test test test test test test test test test test test test test test\\
5. test test test test test test test test test test test test test test test test test\\
\end{document}

Codes above give such result:

result 1

But If I add a sentence before wrapfigure environment, it will give extra vertical space like this:

Code:

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{wrapfig}
\begin{document}
\noindent
1. test test test test test test test test test test\par
\noindent
\begin{wrapfigure}[4]{r}{0pt}
    \includegraphics[width=2cm]{test.png}
\end{wrapfigure}
2. test test test test test test test test test test test test test\\
3. test test test test test test test test test test test test test test test test test test test test\\
4. test test test test test test test test test test test test test test test test test test test test test test test test test test\\
5. test test test test test test test test test test test test test test test test test\\
\end{document}

Result:

result 2

I tried to use vspace* in wrapfigure environment, but it didn't work.

So how to remove that extra vertical space?

Thanks for your time and effort.

1

The insbox plain TeX macro package doesn't have this problem: it defines the \InsertBoxL and \InsertBoxR commands, which take two mandatory arguments: the number of unshortened lines before insertion of the box, and the inserted object, and a last optional argument – the number of supplementary shorter lines, in case TeX calculates the wrong number of shorter lines.

Note that, as the inserted image is not a float, if you need a caption, you will have to use \captionof{figure}{…}.

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{wrapfig}
\input{insbox}

\begin{document}

\InsertBoxR{1}{ \includegraphics[width=3cm]{sunstar}}
\noindent
1. test test test test test test test test test test\par
\noindent
2. test test test test test test test test test test test test test\\
3. test test test test test test test test test test test test test test test test test test test test\\
4. test test test test test test test test test test test test test test test test test test test test test test test test test test\\
5. test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test\\\

\end{document} 

enter image description here

| improve this answer | |
1

The extra vertical spacing stems from the \intextsep length. Setting this to zero removes the space.

For more information, you might want to check out this Stack Exchange question.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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