Where does the space before wrapfigure comes from and how can it be eliminated?

You are top-aligning your minipages. If a minipage (or some other box) starts with normal text then "top-aligning" means that its baseline is at the baseline of the first text line. But if it starts with some \vspace then this determines the baseline.

Inside a minipage wrapfig adds at first a zero \vspace. The easiest way to "avoid" the gap is to add a similar space to the other minipage, to adjust their baseline in a similar way:

\documentclass{article}
\usepackage{lipsum,tikz}
\usepackage{wrapfig}

\setlength\intextsep{0pt}
\begin{document}

\fbox{%
\begin{minipage}[t]{0.32\textwidth}
    \begin{wrapfigure}{r}{2cm}%
        \begin{tikzpicture}%
            \fill (0, 0) rectangle (2, 2);%
        \end{tikzpicture}%
    \end{wrapfigure}%

    \lipsum[1]%
\end{minipage}%
}%
%
\fbox{%
\begin{minipage}[t]{0.32\textwidth}%
\vspace{0pt}
    \lipsum[1]%
\end{minipage}%
}%
\fbox{%
\begin{minipage}[t]{0.32\textwidth}%
    \lipsum[1]%
\end{minipage}%
}%

\end{document}

enter image description here


I fixed it ;)

\documentclass{article}
\usepackage{lipsum,tikz,wrapfig}

\setlength\intextsep{-1.8pt}%<- doesn't seem to matter


\begin{document}

\begin{minipage}[t]{0.45\textwidth}%
    \begin{wrapfigure}{r}{4cm}%
        \begin{tikzpicture}%
            \fill (0, 0) rectangle (4, 4);%
        \end{tikzpicture}%
    \end{wrapfigure}%
    \vspace*{-6.7pt}

    \lipsum[1]%
\end{minipage}%
\begin{minipage}[t]{0.45\textwidth}%
%   \begin{wrapfigure}{r}{4cm}%
%       \begin{tikzpicture}%
%       \fill (0, 0) rectangle (4, 4);%
%       \end{tikzpicture}%
%   \end{wrapfigure}%

    \lipsum[1]%
\end{minipage}%
\end{document}

Just uploaded for you to see if you can figure out what that numbers needed are...

enter image description here