> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/latex/zh-cn/latex-cuo-wu/26-missing-number-treated-as-zero.md).

# 缺少数字，按零处理

当你在 count、dimension 或 skip 条目中写入了某个不是数字的内容时，会出现此错误。如果这样做，你会生成下面的错误信息：

main.tex，第 5 行

缺少数字，已按 0 处理。

l t l.8 \vspace{this should be a number} 这里本应有一个数字；我插入了 \`0'。（如果你弄不明白为什么我需要看到一个数字，请在《The TeXbook》的索引中查找 \`weird error'。）

## 常见原因

**在需要数字的地方忘记填写数字：**

产生此错误最基本的方式，是在某个需要数字的命令中忘记提供数字。下面给出一个示例。

```latex
我们想在这里和

\vspace{this should be a number}

之间插入一些垂直间距。
```

这里， **`\vspace{...}`** 命令期望其参数是一个数字，用来告诉它在文本之间保留多少垂直间距。由于这里没有数字，因此会出现错误。正确的写法是

```latex
我们想在这里和

\vspace{6em}

之间插入一些垂直间距。
```

![Missingnumbervspace.PNG](/files/f55e7552fcaf78a27d2e7e89479bf572c9a80e2d)

有许多像……这样的命令 **`\vspace{...}`** 它们都需要数字作为参数。最常见的有

* 诸如以下的间距命令：
  * **`\vspace{...}`**
  * **`\vspace*{...}`**
  * **`\hspace{...}`**
  * **`\hspace*{...}`**
* 缩放命令，例如 **`\includegraphics[scale = 0.7]{image}`**。这会将你的图片缩放为 **`0.7`** 倍于其实际大小。这里其他需要数字的选项有：
  * **`宽度`**
  * **`高度`**
  * **`page`**
  * **`分辨率`**
  * **`裁剪`**
  * **`angle`**.
* 该 **`\linebreak[number]`** 命令，其中参数表示你想跳过多少行。
* 计数器命令，例如：
  * **`\addtocounter{mycounter}{number}`**
  * **`\setcounter{mycounter}{number}`**
* 长度设置命令，例如 **`\setlenght{\lengthname}{number}`**。这会改变某个特定长度的值，例如 **`\textwidth`** 为 **`number`** （例如 **`\setlength{\textwidth}{1in}`**).
* 表格选项命令，例如 **`\multicolumn{number}{c}{Table entry}`**.

**换行符 \\\ 后面跟着方括号：**

如果换行命令 **`\\`** 后面跟着方括号 **`[...]`**，它将被视为一个可选参数，因此方括号内会被期望是一个数字。即使在……之间有空格和换行，也同样如此 **`\\`** 和 **`[...]`** 命令。这个问题常常出现在表格中，如下所示：

```latex
\begin{tabular}{c|c}
    [x] &  2\\
    [x]^2 & 4
\end{tabular}
```

这会产生错误，因为在第三行中，我们有一个换行符后面跟着方括号。LaTeX 期望方括号内是一个数字，但却找到了 **`x`**。正确写出上表的方法是将方括号放在花括号内 **`{...}`** 如下所示：

```latex
\begin{tabular}{c|c}
    [x] &  2\\
    {[x]}^2 & 4
\end{tabular}
```

**使用 subfigure 宏包：**

该 **`subfigure`** 宏包早已过时，而且即使没有实际错误，也会产生“Missing number”错误。下面是一个示例：

```latex
% 在导言区中
\usepackage{subfigure}

% In the body of your document
\begin{figure}
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[scale=0.2]{image}
        \caption{A gull}
        \label{fig:gull}
    \end{subfigure}%
\end{figure}
```

这会产生错误，因为 subfigure 宏包无法识别 **`\textwidth`** 将其视为数字，而它实际上是一个数字（相当于页面上整段文本块的固定宽度）。解决这个问题的方法是使用更新的 **`subcaption`** 宏包，它已经取代了 **`subfigure`**。 **`\usepackage{subcaption}`** 在导言区中替代 **`\usepackage{subfigure}`** 将会得到所需结果，且不会出现任何错误。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/latex/zh-cn/latex-cuo-wu/26-missing-number-treated-as-zero.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
