[Tex/LaTex] placing table and figure side by side

floatssidebysidetables

The following code places the figure and table one after another instead of side by side.

What's going wrong?

\begin{figure}
\begin{minipage}[t]{0.4\linewidth}
\centering
\caption{}\label{fig}
\includegraphics[scale=.4]{image}\label{}
\end{minipage}
\end{figure}
\hfill
\begin{table}
\begin{minipage}{0.5\linewidth}
\begin{center}
\caption{}\label{}
\scalebox{0.9}{
\setlength{\tabcolsep}{.6em}
\begin{tabular}{ |c c c c c | } 

\end{tabular}
}
\end{center}
\end{minipage}
\end{table}

Best Answer

A figure and table environment always appear in the full width of a line and with nothing next to them. If you want to place the two next to each other, you can't use a figure AND a table environment. If you still want them to float you can use only one of the two environments and use \captionof{<type>}{<caption>} instead (this is provided by the capt-of package, the caption package, or any KOMA-script class).

Small example:

\documentclass[]{article}

\usepackage{capt-of}
\usepackage[]{graphicx}

\begin{document}
\begin{figure}
  \begin{minipage}[t]{.4\linewidth}
    \centering
    \includegraphics{example-image-duck}%
    \caption
      {%
        Image of a duck%
        \label{fig:duck}%
      }%
  \end{minipage}\hfill
  \begin{minipage}[t]{.4\linewidth}
    \centering
    \begin{tabular}{ll}
      Duck type & description \\
    \end{tabular}
    \captionof{table}
      {%
        Different kinds of ducks%
        \label{tab:duck}%
      }
  \end{minipage}
\end{figure}

\end{document}

enter image description here

Related Question