18

I was ok doing my college work, then I needed to put figures on it. I looked at the Wikipedia's example where it used subfigures, so I tried to use in my work.

The following block (copy-and-paste with changed figure paths):

\begin{figure}
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{multiple/Torrentcomp_small-0.png}
        \caption{A gull}
        \label{fig:gull}
    \end{subfigure}%
    ~ %add desired spacing between images, e. g. ~, \quad, \qquad etc.
      %(or a blank line to force the subfigure onto a new line)
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{multiple/Torrentcomp_small-0.png}
        \caption{A tiger}
        \label{fig:tiger}
    \end{subfigure}
    ~ %add desired spacing between images, e. g. ~, \quad, \qquad etc.
      %(or a blank line to force the subfigure onto a new line)
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{multiple/Torrentcomp_small-0.png}
        \caption{A mouse}
        \label{fig:mouse}
    \end{subfigure}
    \caption{Pictures of animals}\label{fig:animals}
\end{figure}

I compiled and then got the following log before some preexistent warnings

./Chapters/Chapter3.tex:26: Missing number, treated as zero. [        \begin{subfigure}[b]{0.3\textwidth}]
./Chapters/Chapter3.tex:26: Illegal unit of measure (pt inserted). [        \begin{subfigure}[b]{0.3\textwidth}]
./Chapters/Chapter3.tex:33: Missing number, treated as zero. [        \begin{subfigure}[b]{0.3\textwidth}]
./Chapters/Chapter3.tex:33: Illegal unit of measure (pt inserted). [        \begin{subfigure}[b]{0.3\textwidth}]
./Chapters/Chapter3.tex:40: Missing number, treated as zero. [        \begin{subfigure}[b]{0.3\textwidth}]
./Chapters/Chapter3.tex:40: Illegal unit of measure (pt inserted). [        \begin{subfigure}[b]{0.3\textwidth}]

(...)

./Chapters/Chapter3.tex:46: LaTeX Warning: Float too large for page by 833.1359pt on input line 46.

I thought that it was that \textwidth fault, but then \the\textwidth printed some value. So, I'm stuck in this. =/

28

You are probably using an obsolete package, subfigure. Use subcaption instead.

Taking the subcaption example from wikibooks (name of *.png changed):

\documentclass{article}

\usepackage{graphicx}
%\usepackage{subfigure}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{it}
        \caption{A gull}
        \label{fig:gull}
    \end{subfigure}%
    ~ %add desired spacing between images, e. g. ~, \quad, \qquad etc.
      %(or a blank line to force the subfigure onto a new line)
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{it}
        \caption{A tiger}
        \label{fig:tiger}
    \end{subfigure}
    ~ %add desired spacing between images, e. g. ~, \quad, \qquad etc.
      %(or a blank line to force the subfigure onto a new line)
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{it}
        \caption{A mouse}
        \label{fig:mouse}
    \end{subfigure}
    \caption{Pictures of animals}\label{fig:animals}
\end{figure}

\end{document}

enter image description here

  • 4
    That did the trick. How could I know that that package was deprecated? – paulochf Oct 19 '13 at 4:42
  • I've just discovered that there's a package called nag that will do that for you ctan.org/tex-archive/macros/latex/contrib/nag – Matti Lyra Feb 1 '16 at 17:31
  • This no longer works for me. I get an error saying \captionwidth already defined. – StatsSorceress Jul 3 '17 at 20:28
  • Undefined control sequence for each caption when I replace package subfigure with subcaption ?! – IceFire Apr 26 at 15:01
3

Maybe the problem is that the name of your file contains an underscore ("_"). We had the same problem and it was fixed changing the name of the file.

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.