> For the complete documentation index, see [llms.txt](https://overleaf-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://overleaf-pro.ayaka.space/latex/zh-cn/latex-cuo-wu/26-missing-number-treated-as-zero.md).

# 缺少数字，按 0 处理

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

main.tex，第 5 行

缺少数字，已按零处理。

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

## 常见原因

**忘记在需要数字的地方包含数字：**

导致此错误的最基本方式是，你忘记在需要数字的命令中加入数字。下面展示了一个例子。

```latex
我们想在这里插入一些垂直间距

\vspace{这里应该是一个数字}

和这里。
```

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

```latex
我们想在这里插入一些垂直间距

\vspace{6em}

和这里。
```

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

有许多像 **`\vspace{...}`** 这样的命令，它们要求参数是数字。其中最常见的是

* 诸如以下的间距命令：
  * **`\vspace{...}`**
  * **`\vspace*{...}`**
  * **`\hspace{...}`**
  * **`\hspace*{...}`**
* 诸如以下的缩放命令 **`\includegraphics[scale = 0.7]{image}`**。这会将你的图像缩放为 **`0.7`** 倍于其实际大小。这里可用的其他需要数字的选项是：
  * **`宽度`**
  * **`高度`**
  * **`page`**
  * **`分辨率`**
  * **`裁剪`**
  * **`尖括号`**.
* 该 **`\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}

% 在文档正文中
\begin{figure}
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[scale=0.2]{image}
        \caption{一只海鸥}
        \label{fig:gull}
    \end{subfigure}%
\end{figure}
```

这会产生一个错误，因为 subfigure 宏包无法识别 **`\textwidth`** 作为一个数字，而实际上它确实是一个数字（相当于页面上整段正文块的固定宽度）。解决方法是使用更新的 **`subcaption`** 宏包，它已经取代了 **`子图`**。将上面的相同代码改写为使用 **`\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://overleaf-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.
