> 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/29-how-to-use-opentype-variable-fonts-with-latex.md).

# 如何在 LaTeX 中使用 OpenType 可变字体

[引言](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 中安装、配置并使用 OpenType 可变字体，重点介绍 LuaLaTeX 和 [fontspec 宏包](https://ctan.org/pkg/fontspec?lang=en)。通过一个引导式的 [Overleaf 项目](https://www.overleaf.com/8438931911svtqtnmfvsrp#28008d)，你将按照分步说明进行学习，内容涵盖实用技巧和必要的背景知识，确保你能够自信地在 LaTeX 文档中使用可变字体。在此过程中，你还将对 LaTeX 字体有更全面的了解，包括如何通过配置合适的可变字体来消除“未定义字体形状”警告。

可变字体为 LaTeX 文档设计提供了无与伦比的灵活性，通过允许你自定义字重和宽度等字体属性，来增强文本呈现效果并提高可读性。它们还有助于解决排版问题，例如在给定空间中容纳更多文本。请注意，本系列仅关注文本字体，因为用于数学排版的可变字体尚不可用。

### 教程内容

* 可变字体简介（本文）
* [步骤 1：设置一个使用可变字体的 Overleaf 项目](/latex/zh-cn/shen-ru-wen-zhang/37-step-1-setting-up-an-overleaf-project-to-use-variable-fonts.md)
* [步骤 2：LaTeX 字体简介](/latex/zh-cn/shen-ru-wen-zhang/38-step-2-an-introduction-to-latex-fonts.md)
* [步骤 3：用可变字体替换 LaTeX 的默认字体](/latex/zh-cn/shen-ru-wen-zhang/39-step-3-replacing-latex-s-default-fonts-with-variable-fonts.md)
* [步骤 4：如何使用 fontspec 配置斜体可变字体](/latex/zh-cn/shen-ru-wen-zhang/40-step-4-how-to-configure-an-italic-variable-font-using-fontspec.md)
* [步骤 5：LaTeX 字重和可变字体的命名实例](/latex/zh-cn/shen-ru-wen-zhang/41-step-5-latex-font-weights-and-named-instances-of-variable-fonts.md)
* [步骤 6：使用可变字体为 Overleaf 项目添加粗体字体](/latex/zh-cn/shen-ru-wen-zhang/42-step-6-using-variable-fonts-to-add-bold-fonts-to-an-overleaf-project.md)
* [步骤 7：在 LaTeX 中使用 Noto Sans 和 Roboto Mono 可变字体](/latex/zh-cn/shen-ru-wen-zhang/43-step-7-using-noto-sans-and-roboto-mono-variable-fonts-with-latex.md)
* [步骤 8：如何创建一个简单的 LaTeX 宏包来配置你的可变字体](/latex/zh-cn/shen-ru-wen-zhang/44-step-8-how-to-create-a-simple-latex-package-to-configure-your-variable-fonts.md)
* [5 个展示如何在 LaTeX 中使用可变字体的 Overleaf 项目](/latex/zh-cn/shen-ru-wen-zhang/35-overleaf-projects-showing-how-to-use-variable-fonts-with-latex.md)

### 可变字体简介

对于排版师、设计师和字体爱好者来说，2016 年 9 月 14 日是一个值得铭记的日子。就在那一天，微软、 [谷歌](https://opensource.googleblog.com/2016/09/introducing-opentype-font-variations.html), [Adobe](https://blog.typekit.com/2016/09/14/variable-fonts-a-new-kind-of-font-for-flexible-design/)和苹果 [公开宣布](https://youtu.be/6kizDePhcFU?feature=shared\&t=250) 了一种名为 [OpenType 字体变体](https://medium.com/variable-fonts/https-medium-com-tiro-introducing-opentype-variable-fonts-12ba6cd2369)的新字体格式，更常被称为 *OpenType 可变字体* ，或者简称为 *可变字体*.

传统上，常规、粗体、半粗体、特粗体、窄体、粗窄体等每种字体样式都需要单独的字体文件，但现在已不再需要了。OpenType 可变字体是一项令人印象深刻的技术，它允许单个字体文件通过调整称为 *设计轴*的内置参数值来生成多种字体样式。下面的视频使用了 Google 的 [Noto Serif 可变字体](https://fonts.google.com/noto/specimen/Noto+Serif/tester).

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/3OhDBHA95DciCRVRgrF4wp/18f8c3f6d15109bf307c48bde9d7c879/VariableFonts.mp4>" %}

来演示这一点。Google 的 Noto Serif 有两个设计轴：宽度和字重，但其他字体可能只有一个轴或多个轴——例如，一款名为 [Recursive](https://fonts.google.com/specimen/Recursive/tester) 的可变字体有五个轴， [有些甚至更多](https://www.axis-praxis.org/specimens/decovar)。字体开发者决定轴的数量及其设计效果。

### 关于设计轴的一些说明

要在 LaTeX（具体来说是 fontspec 和 LuaLaTeX）中使用可变字体，你需要了解以下内容。

* 每个设计轴都由一个简短的四字符“标记”和一个更长、更具描述性的名称来标识。
* OpenType 可变字体规范提供了 [五个已注册的（“标准”）轴](https://learn.microsoft.com/en-us/typography/opentype/spec/dvaraxisreg#registered-axis-tags):

|      |      |
| ---- | ---- |
| 标记   | 名称   |
| ital | 斜体   |
| opsz | 光学大小 |
| slnt | 倾斜   |
| wdth | 宽度   |
| wght | 字重   |

* 从 [2.9a 版本](https://github.com/latex3/fontspec/releases/tag/v2.9a)， [fontspec 宏包](https://ctan.org/pkg/fontspec?lang=en) 开始，你可以使用其名称来设置标准轴的值，例如 `Weight=400`.
* 字体创建者可以自由创建并命名额外的设计轴。fontspec 提供了使用其四字符标记来设置任意设计轴值的功能。
* 设计轴的值范围从最小值到最大值，步长由字体创建者决定。要在 LaTeX（LuaLaTeX）中使用可变字体，你需要了解它的各个轴，以及它们的最小值、最大值和增量（步长）值。
* 目前，可变字体只能用于文档正文文本——还没有可变数学字体。
* Google 维护着一个 [设计轴列表](https://fonts.google.com/variablefonts#axis-definitions) ，其中列出了他们提供的字体当前使用的设计轴，包括四字母设计标记、完整名称以及该轴作用的定义。

### 可变字体需要 LuaLaTeX 和 fontspec 宏包

截至 2024 年 8 月，只有 LuaLaTeX [编译器](/latex/zh-cn/zhi-shi-ku/026-changing-compiler.md) 支持 OpenType 可变字体——pdfLaTeX 和 XeLaTeX 不支持。

使用 LuaLaTeX 处理 OpenType 字体需要 fontspec 宏包，它提供面向用户的命令，以访问一个更底层、也更技术化的字体加载系统，称为 [luaotfload](https://ctan.org/pkg/luaotfload?lang=en)。虽然完全可以直接使用 luaotfload 的功能，但大多数人更喜欢 fontspec 的简便和易用。

[TeX Live 2024](https://www.overleaf.com/blog/tex-live-2024-is-now-available) 包含了 fontspec 2.9a 版本，该版本于 2024 年 2 月 13 日发布，增加了额外功能，使使用可变字体更加容易。

### 我在哪里可以找到并探索一些可变字体？

访问 Google Fonts 是一个极好的起点——尤其是 [列出字体家族及其设计轴的页面](https://fonts.google.com/variablefonts)。一旦你找到感兴趣的字体，就进入它的 *字体测试器* 页面，并使用提供的控件调整其设计轴。

该 [Axis-Praxis 网站](https://www.axis-praxis.org) 让你可以尝试许多可变字体，其中一些展示了有趣的设计可能性——包括 [Decovar](https://www.axis-praxis.org/specimens/decovar)，这是一款拥有 12 个设计轴的实验性字体。你也可以将可变字体上传到 Axis-Praxis，并使用该平台自动生成的控件来测试并调整设计轴值。

另一个有用的网站是 <https://v-fonts.com/>，其用途描述为“一个用于查找和试用可变字体的简单资源”。

[引言](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)


---

# 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/29-how-to-use-opentype-variable-fonts-with-latex.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.
