> 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-tw/latex-cuo-wu/26-missing-number-treated-as-zero.md).

# 缺少數字，視為 0

當你在 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/4db0824cb9271926195bfbbdc8b644f4d152d925)

有許多像 **`\vspace{...}`** 這樣需要數字作為參數的指令。最常見的有

* 間距指令，例如：
  * **`\vspace{...}`**
  * **`\vspace*{...}`**
  * **`\hspace{...}`**
  * **`\hspace*{...}`**
* 縮放指令，例如 **`\includegraphics[scale = 0.7]{image}`**。這會將你的圖片縮放為 **`0.7`** 倍的實際大小。這裡其他需要數字的選項有：
  * **`寬度`**
  * **`高度`**
  * **`頁面上看到的最後一個標記`**
  * **`解析度`**
  * **`裁切`**
  * **`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}

% 在你的文件正文中
\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`** 套件，它已取代 **`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://overleaf-pro.ayaka.space/latex/zh-tw/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.
