> 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/shen-du-wen-zhang/40-step-4-how-to-configure-an-italic-variable-font-using-fontspec.md).

# 步骤 4：如何使用 fontspec 配置斜体可变字体

[引言](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 目前警告我们的项目中缺少三种字体形状：

![显示 LaTeX 缺少字体警告的图片。](/files/91a8f74692f31c9647e16ef71ccd82e02f9be186)

这些内容已在下表中汇总，但请记住，系列标识符中会去掉 m *除非* 其中 *两个* 宽度和字重为 m（中等）。在本文中，我们将展示如何通过添加一个中等字重、中等宽度且为斜体形状的字体来修复第二个警告。

| **警告编号** | **警告说明**                             | **系列标识符** | **字重** | **宽度** | **形状** |
| -------- | ------------------------------------ | --------- | ------ | ------ | ------ |
| 1        | **b**旧字重， **m**中等宽度字体的 **n**正常（直立）形状 | b         | b      | m      | n      |
| 2        | **m**中等字重， **m**中等宽度字体的 **斜**体形状     | m         | m      | m      | 斜      |
| 3        | **b**旧字重， **m**中等宽度字体的 **斜**体形状      | b         | b      | m      | 斜      |

## Noto Serif 的两个字体文件

直立和斜体字体样式（字体）的设计通常差异太大，难以通过可变字体中的某个设计轴在二者之间实现平滑过渡。直立和斜体形状各自都需要一个专用字体文件，以保留其设计的独特特征。因此，Overleaf 教程项目包含以下 Noto Serif 文件：

* 用于直立形状： `NotoSerif-VariableFont-wdth-wght.ttf`
* 用于斜体形状： `NotoSerif-Italic-VariableFont-wdth-wght.ttf`

## 如何添加 Noto Serif 斜体字体

我们的主文档文本字体 Noto Serif 是使用 fontspec 的 `\setmainfont` 命令：

```
\setmainfont{NotoSerif-VariableFont-wdth-wght.ttf}
```

提醒一下， `\setmainfont` 具有以下一般形式

```
\setmainfont{⟨font⟩}[⟨font features⟩]
```

我们可以使用可选的 `⟨font features⟩` 通过 fontspec 的 `ItalicFont` 键，为主文档字体启用斜体形状。

### 配置斜体可变字体

按照以下步骤激活（配置）Noto Serif 斜体可变字体。

1. 确保打开在第 3 步中配置的教程项目。
2. 将这一行替换为

```
\setmainfont{NotoSerif-VariableFont-wdth-wght.ttf}
```

以下内容

```
\setmainfont{NotoSerif-VariableFont-wdth-wght.ttf}
[
ItalicFont=NotoSerif-Italic-VariableFont-wdth-wght.ttf
]
```

6. 重新编译并注意以下几点。

* 现在有两个未定义形状警告，比之前少一个：

![显示 LaTeX 缺少字体警告的图片。](/files/1eb0709a0484c4b6fe5a7728b322a5f92d18cc46)

这些警告是由于缺少正常（n）和斜体（it）字体形状的粗体字体所致。

* 以下警告不再出现：

``字体形状 `TU/NotoSerif-VariableFont-wdth-wght.ttf(0)/m/it' 未定义``

* 由于 LaTeX 现在可以访问位于 `NotoSerif-VariableFont-wdth-wght.ttf(0)` 字体族中的中等字重、中等宽度（系列）的斜体（形状）字体，排版后的文档中斜体文本又重新出现了。

## 在下一步中

在第 5 步中，我们将了解可变字体字重，为第 6 步做准备，并在那里完成可变字体的初始配置。


---

# 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/shen-du-wen-zhang/40-step-4-how-to-configure-an-italic-variable-font-using-fontspec.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.
