> 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/shen-ru-wen-zhang/41-step-5-latex-font-weights-and-named-instances-of-variable-fonts.md).

# 步骤 5：LaTeX 字重和可变字体的命名实例

[简介](https://www.overleaf.com/learn/latex/Articles/How_to_use_OpenType_variable_fonts_with_LaTeX?preview=true) [步骤 1](https://www.overleaf.com/learn/latex/Articles/Step_1:_Setting_up_an_Overleaf_project_to_use_variable_fonts?preview=true) [步骤 2](https://www.overleaf.com/learn/latex/Articles/Step_2:_An_introduction_to_LaTeX_fonts?preview=true) [步骤 3](https://www.overleaf.com/learn/latex/Articles/Step_3:_Replacing_LaTeX’s_default_fonts_with_variable_fonts?preview=true) [步骤 4](https://www.overleaf.com/learn/latex/Articles/Step_4:_How_to_configure_an_italic_variable_font_using_fontspec?preview=true) [步骤 5](https://www.overleaf.com/learn/latex/Articles/Step_5:_LaTeX_font_weights_and_named_instances_of_variable_fonts?preview=true) [步骤 6](https://www.overleaf.com/learn/latex/Articles/Step_6:_Using_variable_fonts_to_add_bold_fonts_to_an_Overleaf_project?preview=true) [步骤 7](https://www.overleaf.com/learn/latex/Articles/Step_7:_Using_Noto_Sans_and_Roboto_Mono_variable_fonts_with_LaTeX?preview=true) [步骤 8](https://www.overleaf.com/learn/latex/Articles/Step_8:_How_to_create_a_simple_LaTeX_package_to_configure_your_variable_fonts?preview=true) [示例与项目](https://www.overleaf.com/learn/latex/Articles/Overleaf_projects_showing_how_to_use_variable_fonts_with_LaTeX?preview=true)

在这一步中，我们演示两种为可变字体的字重设置数值的方法，以中等字重作为起点。我们介绍可变字体的命名实例，并探讨它们如何与 LaTeX 的标准字重相关联。

请确保你打开的是在第 4 步中配置的教程项目。

## 设置设计轴值的两种方法

Google 的字体测试页提供了两种设置可变字体设计轴值的方法：使用滑块，或使用包含名称和值的下拉列表。 [Noto Serif 的测试页](https://fonts.google.com/noto/specimen/Noto+Serif/tester) 提供了一个从 100 到 900 的字重轴滑块，以及一个表示不同字体字重的命名实例列表。

![展示设置设计轴值的两种方法：使用滑块或命名实例的图片](/files/8d8d744d8a981fb096401fbe8d2f3d183b912e0b)

### 什么是可变字体的“实例”？

可变字体的 *实例* 是用于创建多种可能样式变化之一的一组特定轴值。为一组轴值赋予名称就定义了一个命名实例。命名实例的数据存储在可变字体文件中。

## LaTeX 中字体字重的名称

如第 2 步所述，LaTeX 定义了九种标准字重，每种都有一个简短标识符和一个更长的描述名称：

|                 |                |
| --------------- | -------------- |
| **LaTeX 字重标识符** | **LaTeX 字重名称** |
| ul              | 超细体            |
| el              | 特细体            |
| l               | 细体             |
| sl              | 半细体            |
| m               | 中等（常规）         |
| sb              | 半粗体            |
| b               | 粗体             |
| eb              | 特粗体            |
| ub              | 超粗体            |

Noto Serif 的字重轴值范围是 100 到 900，恰好以 100 为步进提供了九个命名实例值。如下表所示，每个命名实例都可以对应到 LaTeX 的九种标准字重之一。

|              |              |       |        |
| ------------ | ------------ | ----- | ------ |
| **LaTeX 字重** | **可变字体命名实例** |       |        |
| *LaTeX 标识符*  | *名称*         | *字重值* | *实例名称* |
| ul           | 超细体          | 100   | 细体     |
| el           | 特细体          | 200   | 特细体    |
| l            | 细体           | 300   | 细体     |
| sl           | 半细体          | 400   | 常规     |
| m            | 中等（常规）       | 500   | 中等     |
| sb           | 半粗体          | 600   | 半粗体    |
| b            | 粗体           | 700   | 粗体     |
| eb           | 特粗体          | 800   | 特粗体    |
| ub           | 超粗体          | 900   | 黑体     |

## 为 LaTeX 的“medium”（常规）字重选择一个值

在 LaTeX 中，“medium”和“regular”字重指的是同一回事：即用于文档主体文本的字重。这与 Noto Serif 的命名实例不同，在那里 Regular 字重为 400，而 Medium 字重为 500。由我们决定为 LaTeX 的 medium 字重选择哪个值。我们会尝试 400，但如果它不起作用（看起来不美观），那么我们就可以轻松切换到另一个值——这种排印控制，正是可变字体的优势。

### 为中等字重的可变字体设置数值

在添加粗体字体之前，我们应该为项目中使用的 Noto Serif 字体的 LaTeX medium（常规）字重设置一个值。

fontspec 提供了两个用于设置字重轴值的功能：

* Weight = ⟨value⟩ 将字重轴设置为任何受支持的 ⟨value⟩
* Instance = ⟨named instance⟩ 将字重设置为由 ⟨named instance⟩ 设定所定义的值

### 将中等字重设置为 400

要将中等字重设置为 400，请将当前项目的 \setmainfont 命令编辑为以下内容

```
\setmainfont{NotoSerif-VariableFont-wdth-wght.ttf}[
Weight=400,
% 或者我们可以将 Weight=400 替换为
% Instance=Regular,
ItalicFont=NotoSerif-Italic-VariableFont-wdth-wght.ttf
]
```

斜体字体的字重轴值也将是 400。

如果在重新编译文档后，你不喜欢排版结果，可以尝试以下方法：

* 为 Weight 轴使用不同的值
* 使用 `\fontsize` 命令尝试调整字号和行距；例如，可以试着写

```
\fontsize{9}{11}\selectfont
```

紧接在 `\begin{document}`

## 在下一步中

在下一步中，我们将配置可变字体以提供粗体和粗斜体字体。


---

# 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/shen-ru-wen-zhang/41-step-5-latex-font-weights-and-named-instances-of-variable-fonts.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.
