> 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/10-illegal-unit-of-measure-pt-inserted.md).

# 非法的度量單位（已插入 pt）

如果您在 LaTeX 中指定長度，但沒有指定適當的單位，您就會產生下列錯誤：

main.tex，第 5 行

非法的度量單位（已插入 pt）。

\vskip l.11 \vspace{6} 維度可以使用 em、ex、in、pt、pc、cm、mm、dd、cc、nd、nc、bp 或 sp 等單位；但您使用的是一個新的單位！我會假設您的意思是 pt，也就是印刷點。若要從這個錯誤中順利復原，最好刪除錯誤的單位；例如，輸入 \`2' 來刪除兩個字母。（參見《The TeXbook》第 27 章。）

參見 [這裡](/latex/zh-tw/ge-shi-hua/01-lengths-in-latex.md) 以進一步了解 LaTeX 中的長度。

## 常見原因

**在指定長度時忘記包含適當的單位：**

此錯誤最常見的原因，只是因為在 LaTeX 中指定長度時忘了加入單位。下方顯示了一個錯誤範例

```latex
下圖應該要有 5 公分寬

\includegraphics[width=5]{image}
```

這裡的錯誤在於，影像的寬度被寫成 **`width=5`**。LaTeX 無法判斷這張圖片應該是五英吋、五公尺、五毫米等等。正確的指定方式是 **`width=5cm`**。這樣可讓 LaTeX 知道圖片應該是五公分寬。

**使用了 LaTeX 中不允許的單位：**

此錯誤出現的另一個常見原因，是您使用了 LaTeX 中不允許的單位。下方顯示了一個例子，其中嘗試將圖片指定為一英尺寬：

```latex
下圖應該要有一英尺寬

\includegraphics[width=1ft]{image}
```

這會產生錯誤，因為英尺不是 LaTeX 中允許的單位。正確的寫法應該是將圖片寬度寫成 **`width=12in`**，這樣就會得到一張一英尺寬的圖片。以下是 LaTeX 中可用單位的列表：

| 縮寫     | 值                                                                                             |
| ------ | --------------------------------------------------------------------------------------------- |
| **pt** | 一個 point 約略等於 1/72.27 英吋，這表示大約 0.0138 英吋或 0.3515 毫米（嚴格來說，point 定義為美制 *印刷英尺* 也就是英制英尺的 249/250） |
| **mm** | 毫米                                                                                            |
| **cm** | 公分                                                                                            |
| **在**  | 英吋                                                                                            |
| **ex** | 大致為目前字型中小寫 'x' 的高度（取決於所使用的字型）                                                                 |
| **em** | 大致為目前字型中大寫 'M' 的寬度（取決於所使用的字型）                                                                 |
| **mu** | 數學單位，等於 1/18 em，其中 em 取自數學符號字族                                                                |

**在錯誤的位置出現了不可展開的標記**

上面其實就是這種情況。TeX 會將長度解析為：任意數量的數字，後接一個可選的小數點，再接任意數量的數字，再接一個可選的空白，最後接任何有效單位。當 TeX 搜尋長度時，它會展開每一個可展開的標記（巨集），直到找到第一個不可展開的標記。

**在換行 \\\ 後面接方括號：**

如果換行指令 **`\\`** 後面接上方括號 **`[...]`**，它將被視為一個可選引數，因此方括號內預期會是一個帶有單位的數字即使在 **`\\`** 以及 **`[...]`** 指令之間有空白和換行，這種情況仍然成立。這個問題常出現在表格中，如下所示：

```latex
\begin{tabular}{c|c}
    [t] & s\\
    [I] & A\\
    [m] & kg
\end{tabular}
```

這會產生錯誤，因為在第三行中，我們有一個換行後面接著方括號。LaTeX 預期方括號內是一個帶有單位的數字，但實際找到的是 **`x`**。上表的正確寫法是將方括號放入大括號中 **`{...}`** 如下所示，或者如果大括號的分組效果不理想，則在其前面加上一個 **`\relax`** ：

```latex
\begin{tabular}{c|c}
    [t] &  s\\
    {[I]} & A\\\relax
    [m] & kg
\end{tabular}
```

**使用 subfigure 套件：**

該 **`subfigure`** 套件已經過時很久了，而且在沒有任何錯誤的情況下，會產生「非法的度量單位」錯誤。下方顯示了一個例子：

```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/10-illegal-unit-of-measure-pt-inserted.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.
