[Tex/LaTex] How to float/wrap text around a table

tableswrapfigure

I've been trying to use the wrapfigure and wraptable from the wrapfig package, but to no avail.

This works for text.

\begin{wrapfigure}{l}{40mm}
    \begin{center}          
        Some random text
    \end{center}
\end{wrapfigure}

This should be to the left of the table. \blindtext

But once I add a table (see code below), it fails.

\begin{wrapfigure}{l}{40mm}
    \begin{center}
        \begin{table}
            \begin{tabular}{l | c}
            A & Cell 1 \\ \hline
            B & Cell 2 \\ \hline
            \end{tabular}
        \end{table} \\
        Some random text
    \end{center}
\end{wrapfigure}

This should be to the left of the table. \blindtext

What am I doing wrong?

Thanks.

Best Answer

The table environment is for normal floating tables. You do not need to put a tabular inside a table environment. You should use the wraptable environment instead.

\begin{wraptable}{l}{40mm}
    \begin{tabular}{l | c}
      A & Cell 1 \\ \hline
      B & Cell 2 \\ \hline
    \end{tabular}
   Some random text
\end{wraptable}

This should be to the left of the table. \blindtext