[Tex/LaTex] No graphics in subfigures

subfloats

So, I have been trying to add three images in a single line.
When I use only the 'figure' function like this

    \begin{figure}[t]
    \includegraphics[width=0.3\linewidth]{./Figures/img1}
    \includegraphics[width=0.3\linewidth]{./Figures/img2}
    \includegraphics[width=0.3\linewidth]{./Figures/img3}
    \end{figure}

I get the result that I want.
But once I try using 'subfigure' function like this

\begin{figure}[t]
\begin{subfigure}
\includegraphics[width=0.3\linewidth]{./Figures/img1}
\end{subfigure}
\begin{subfigure}
\includegraphics[width=0.3\linewidth]{./Figures/img2}
\end{subfigure}
\begin{subfigure}
\includegraphics[width=0.3\linewidth]{./Figures/img3}
\end{subfigure}
\end{figure}

I just get three empty boxes in a row and with 'relax.png' writtten inside them. Moreover, I get a load of errors as well which weren' there when I only used figures.

Best Answer

Don't use both packages.

\documentclass{article}
\usepackage{subcaption}
\usepackage{subfigure}
\begin{document}
abc
\end{document}

will throw the error

! LaTeX Error: Command \c@subfigure already defined.
               Or name \end... illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.113 \newcounter{subfigure}
                            [figure]

while

\documentclass{article}
\usepackage{subfigure}
\usepackage{subcaption}
\begin{document}
abc
\end{document}

throws

! Package subcaption Error: This package can't be used in cooperation
(subcaption)                with the subfigure package.

See the subcaption package documentation for explanation.

The subfigure package is considered deprecated, so I'd recommend subcaption. They differ in use however:

  • \usepackage{subfigure}: defines a \subfigure macro, used as \subfigure[<subcaption>]{<figure>}
  • \usepackage{subcaption}: defines an environment, used as

    \begin{subfigure}{<width>}
    <figure>
    \caption{<caption>}
    \end{subfigure}
    

    Note that you have to specify a width for the environment, similar to minipage. Hence, a working version of your code snippet would be

    \documentclass{article}
    \usepackage[demo]{graphicx}
    \usepackage{subcaption}
    \begin{document}
    \begin{figure}[t]
    \begin{subfigure}{0.3\linewidth}
    \includegraphics[width=\linewidth]{./Figures/img1}
    \end{subfigure}\hfill
    \begin{subfigure}{0.3\linewidth}
    \includegraphics[width=\linewidth]{./Figures/img2}
    \end{subfigure}\hfill
    \begin{subfigure}{0.3\linewidth}
    \includegraphics[width=\linewidth]{./Figures/img3}
    \end{subfigure}
    \end{figure}
    \end{document}