> 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/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 步中，我们使用字重轴值 400 为文档主文本字体 Noto Serif 的正体和斜体样式设置了中等字重。在这一步中，我们将展示如何为常规（正体）和斜体样式配置 Noto Serif 以提供粗体字体。

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

## 未定义粗体字体的警告

重新编译当前项目后，LaTeX 会给出以下警告：

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

这些警告汇总在下表中。请记住，系列标识符中的 m 会被去掉 *除非* 其中 *两个* 宽度和字重都是 m（中等）。

| **警告编号** | **警告说明**     | **系列标识符** | **字重** | **宽度** | **形状** |
| -------- | ------------ | --------- | ------ | ------ | ------ |
| 1        | 粗体、中等宽度、正体字体 | b         | b      | m      | n      |
| 2        | 粗体、中等宽度、斜体字体 | b         | b      | m      | 斜      |

我们将展示如何通过为正体（常规）和斜体字体形状配置粗体字体来修复这些问题。

## 使用变量字体的字重轴添加粗体字体

粗体正体和粗体斜体文本的字体可以使用 fontspec 的 `FontFace` 键进行配置，其形式如下

```
FontFace = {⟨series⟩}{⟨shape⟩}{Font = ⟨font name⟩, ⟨features⟩}
```

其中

* `⟨series⟩` 是 LaTeX 的系列标识符（链接到该部分）
* `⟨shape⟩` 是 LaTeX 的字形标识符（链接到该部分）
* `⟨font name⟩` 是字体文件名或字体名称
* `⟨features⟩` 包含我们将用于配置变量字体的设置，例如为正体和斜体变量字体设置合适的字重轴值

根据 Noto Serif 的命名实例（LINK）建议的值，我们将使用 600 的字重轴值来为正体和斜体样式配置粗体字体。

### 如何配置粗体、中等宽度、正体字体

我们将使用 `FontFace` 键，并使用以下设置

* `⟨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` 键，并使用以下设置

* `⟨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
大量的 UPPERCASE 字母序列可能会使你的 TYPESET 文本
看起来“typographically UNSIGHTLY”。其 APPEARANCE 可以通过
使用小型大写字母来改进，从而使文本呈现更精致、更 ELEGANT 的效果。

\vskip10pt
大量的 \textsc{uppercase} 字母序列可能会使你的
\textsc{typeset} 文本看起来“typographically \textsc{unsightly}”。
其 \textsc{appearance} 可以通过使用小型大写字母来改进，
从而使文本呈现更精致、更 \textsc{elegant} 的效果。
```

此示例生成如下输出：

![比较使用和未使用小型大写字母排版的文本的图片](/files/d82f360449291d151512cc586e981b15a3508dd5)

### 哪些变量字体启用了小型大写字母？

fontspec 会自动为支持它们的字体启用小型大写字母——我们的三种变量字体都提供小型大写字母。将以下 LaTeX 文本粘贴到你的文档中，以使用这三种字体族排版小型大写字母：

```latex
\begin{itemize}
\item main text family (Noto Serif): \textsc{small caps}
\item sans serif family (Noto Sans): {\sffamily \textsc{small caps}}
\item monospaced family (Roboto Mono): {\ttfamily \textsc{small caps}}
\end{itemize}
```

此示例生成如下输出：

![使用 LaTeX 中 3 种不同变量字体排版小型大写字母的图片](/files/36d3a53b22e78026bfa4c10f9aecd0aff6fb8104)

### 粗体和斜体的小型大写字母呢？

由于我们已经为 Noto Serif 配置了粗体和斜体字体，我们可以用这些样式排版小型大写字母。要用 Noto Serif 排版一段小型大写字母，请将以下代码粘贴到最新的 Overleaf 项目中：

```latex
\begin{itemize}
\item main text family (Noto Serif):
\begin{itemize}
    \item \textsc{regular small caps}
    \item \textit{\scshape italic small caps}
    \item \textbf{\scshape bold small caps}
    \item \textbf{\itshape\scshape bold italic small caps}
\end{itemize}
\end{itemize}
```

这将产生如下输出：

![使用变量字体在 LaTeX 中排版粗体和斜体小型大写字母的图片](/files/9d9bf27e454e52c3ee81a4b3f2939f77a0c6dfbf)

## 在下一步中

在下一步中，我们将为无衬线字体族（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://ayakaleaf-pro.ayaka.space/latex/zh-cn/shen-du-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.
