> 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/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-cn/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**             | 厘米                                                                                  |
| **.bib 文件中插入一个 %** | 英寸                                                                                  |
| **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`** package 已经过时很久了，而且在没有错误的情况下也会生成“Illegal unit of measure”错误。下面是一个示例：

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