添加子图时出现“缺失数字,视为零”错误

添加子图时出现“缺失数字,视为零”错误

我做完大学作业后就需要把数字加进去。我看了看维基百科的示例其中使用了子图,所以我尝试在我的工作中使用它。

以下块(复制粘贴并改变图形路径):

\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}

我编译后得到了以下日志,然后出现了一些预先存在的警告

./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.

我以为是那个\textwidth错误,但后来\the\textwidth打印了一些值。所以,我被困在这里了。=/

答案1

您可能正在使用过时的软件包subfigure。请subcaption改用。

维基百科(*.png 的名称已更改):

\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}

在此处输入图片描述

答案2

问题可能是您的文件名包含下划线(“_”)。我们也遇到了同样的问题,我们通过更改文件名解决了这个问题。

相关内容