> 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/42-step-6-using-variable-fonts-to-add-bold-fonts-to-an-overleaf-project.md).

# 步驟 6：使用可變字型為 Overleaf 專案加入粗體字型

[簡介](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)

在第 5 步中，我們將文件主要文字字型 Noto Serif 的中等字重，透過權重軸值 400，同時套用於直立與斜體樣式。本步驟將示範如何設定 Noto Serif，讓它同時提供一般（直立）與斜體樣式的粗體字型。

請確認你開啟的是在第 5 步中設定好的教學專案。

## 關於未定義粗體字型的警告

重新編譯目前專案後，LaTeX 會發出以下警告：

![顯示 LaTeX 缺少字型警告的圖片。](/files/71acb180130c1bc719097fa8ba209000fc3420fd)

這些警告摘要如下表所示。請記得，系列識別碼中的 m 會被省略 *除了* 其中 *兩個* 寬度與字重為 m（中等）。

| **警告編號** | **警告說明**              | **系列識別碼** | **字重** | **寬度** | **字形** |
| -------- | --------------------- | --------- | ------ | ------ | ------ |
| 1        | 一般（直立）樣式中的粗體字重、中等字寬字型 | b         | b      | m      | n      |
| 2        | 斜體樣式中的粗體字重、中等字寬字型     | b         | b      | m      | 斜      |

我們將示範如何透過為直立（一般）與斜體字型樣式設定粗體字型來修正這些問題。

## 使用變數字型的權重軸加入粗體字型

粗體直立與粗體斜體文字的字型可使用 fontspec 的 `FontFace` key 進行設定，其形式如下

```
FontFace = {⟨系列⟩}{⟨樣式⟩}{Font = ⟨字型名稱⟩, ⟨特性⟩}
```

其中

* `⟨series⟩` 是 LaTeX 的系列識別碼（連結到章節）
* `⟨shape⟩` 是 LaTeX 的字形識別碼（連結到章節）
* `⟨font name⟩` 是字型檔案名稱或字型名稱
* `⟨features⟩` 包含我們將用來設定變數字型的設定，例如為直立與斜體變數字型設定適當的權重軸值

根據 Noto Serif 的命名實例（LINK）所建議的值，我們將使用 600 的權重軸值來為一般（直立）與斜體樣式設定粗體字型。

### 如何設定粗體、中等字寬、直立字型

我們將使用 `FontFace` key，並使用以下設定

* `⟨series⟩` = b
* `⟨shape⟩` = n
* `⟨font name⟩` = NotoSerif-VariableFont-wdth-wght.ttf
* `⟨features⟩` = Weight=600

因此得到

```
FontFace = {b}{n}{Font=NotoSerif-VariableFont-wdth-wght.ttf,Weight=600}
```

### 如何設定粗體、中等字寬、斜體字型

我們將使用 `FontFace` key，並使用以下設定

* `⟨series⟩` = b
* `⟨shape⟩` = it
* `⟨font name⟩` = NotoSerif-Italic-VariableFont-wdth-wght.ttf
* `⟨features⟩` = Weight=600

因此得到

```
FontFace = {b}{it}{Font=NotoSerif-Italic-VariableFont-wdth-wght.ttf,Weight=600}
```

## 整合起來

更新目前專案的 `\setmainfont` 指令，改為使用以下設定：

```latex
\setmainfont{NotoSerif-VariableFont-wdth-wght.ttf}[
Weight=400,
ItalicFont = NotoSerif-Italic-VariableFont-wdth-wght.ttf,
FontFace = {b}{n}{Font = NotoSerif-VariableFont-wdth-wght.ttf,Weight=600},
FontFace = {b}{it}{Font = NotoSerif-Italic-VariableFont-wdth-wght.ttf,Weight=600}
]
```

重新編譯目前專案，即可看到不再有任何未定義樣式的警告。

## 額外功能：免費提供小型大寫字母！

在本節中，我們要指出一個驚喜的額外福利：fontspec 會自動為支援小型大寫字母的字型啟用該功能。

### 什麼是小型大寫字母？

小型大寫字母是一種文字樣式，使用與小寫字母相同高度的大寫字母。它們用於在包含許多大寫單字的文字中作為風格用途，例如技術文字中的縮寫詞或關鍵字。

將以下 LaTeX 文字貼到目前的 Overleaf 專案中，以排版一個比較有無小型大寫字母的範例——請務必將它貼入 *之後* `\begin{document}`。LaTeX 的 `\textsc` 指令用於將文字排版為小型大寫字母。

```latex
大量連續的大寫字母可能會讓你排版出的文字
看起來「在排印上 \textsc{unsightly}」。其外觀可以透過
使用小型大寫字母來改善，讓文字呈現更精緻、更優雅的外觀。

\vskip10pt
大量連續的 \textsc{uppercase} 字母可能會讓你的
\textsc{typeset} 文字看起來「在排印上 \textsc{unsightly}」。
它的 \textsc{appearance} 可透過使用小型大寫字母來改善，
讓文字呈現更精緻、\textsc{elegant} 的外觀。
```

此範例會產生以下輸出：

![比較有無小型大寫字母排版文字的圖片](/files/159290469230cf545c6020850d6926c2a8ab40bf)

### 哪些變數字型已啟用小型大寫字母？

fontspec 會自動為支援小型大寫字母的字型啟用該功能——我們的三款變數字型都提供小型大寫字母。請將以下 LaTeX 文字貼入你的文件中，使用這三個字型家族來排版小型大寫字母：

```latex
\begin{itemize}
\item 主要文字字族（Noto Serif）：\textsc{small caps}
\item 無襯線字族（Noto Sans）：{\sffamily \textsc{small caps}}
\item 等寬字族（Roboto Mono）：{\ttfamily \textsc{small caps}}
\end{itemize}
```

此範例會產生以下輸出：

![顯示在 LaTeX 中使用 3 種不同變數字型排版的小型大寫字母圖片](/files/7c2779136cd17eee5be0d07bf8e47c2576c2e738)

### 那粗體與斜體的小型大寫字母呢？

由於我們已為 Noto Serif 設定粗體與斜體字型，因此可以用那些樣式來排版小型大寫字母。若要使用 Noto Serif 排版一段小型大寫字母，請將以下程式碼貼入最新的 Overleaf 專案：

```latex
\begin{itemize}
\item 主要文字字族（Noto Serif）：
\begin{itemize}
    \item \textsc{常規小型大寫}
    \item \textit{\scshape 斜體小型大寫}
    \item \textbf{\scshape 粗體小型大寫}
    \item \textbf{\itshape\scshape 粗斜體小型大寫}
\end{itemize}
\end{itemize}
```

這會產生以下輸出：

![顯示在 LaTeX 中使用變數字型排版的粗體與斜體小型大寫字母圖片](/files/3677e069e038a345d09241419ca7a04abf39b40f)

## 下一步

在下一步中，我們將為無襯線字族（Noto Sans）和等寬字族（Roboto Mono）設定粗體與斜體字型樣式。


---

# 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/42-step-6-using-variable-fonts-to-add-bold-fonts-to-an-overleaf-project.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.
