> 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-tw/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/3b45ce4478ae83e57370701cbcb8a38dae79a52f)

這些內容已在下表中摘要，但請記得 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/b18a3ab126653152e170e25959d6f1529115d392)

這些警告是因為缺少常規（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://overleaf-pro.ayaka.space/latex/zh-tw/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.
