> 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/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**中等宽度字体的 **斜**alic 形状  | m         | m      | m      | 斜      |
| 3        | **b**粗体字重， **m**中等宽度字体的 **斜**alic 形状  | 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 步做准备，在第 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://overleaf-pro.ayaka.space/latex/zh-cn/shen-ru-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.
