> 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/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 无法判断图像应该是 5 英寸、5 米、5 毫米等。正确的写法是 **`width=5cm`**。这样 LaTeX 就知道图像应为 5 厘米宽。

**使用了 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 宏包：**

该 **`子图`** 该 package 已经过时很久了，在没有错误存在时也会生成一个“Illegal unit of measure”错误。下面给出一个例子：

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