> 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/35-overleaf-projects-showing-how-to-use-variable-fonts-with-latex.md).

# 展示如何在 LaTeX 中使用可變字型的 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)

這篇最終教學文章列出了由 Overleaf 建立的五個專案，用來展示 OpenType 可變字型的使用。所有專案都包含必要的可變字型檔案，以及一個 `latexmkrc` 用來讓 LaTeX 可存取這些字型檔案的檔案。

免費方案的使用者請注意，其中一些專案的初次編譯時間較長，這反映了它們使用 LuaLaTeX 與 OpenType 可變字型。

## 專案 1：一個已設定好 OpenType 可變字型、可直接使用的專案

* 開啟 Overleaf 專案 <https://www.overleaf.com/1311295292wvdkgcbnfxsw#94292d>

本專案已設定為使用 Noto Serif、Noto Sans 和 Roboto Mono。章節標題、圖表標題，甚至註腳都設定為使用特定的可變字型設定——請參閱專案檔案 `myvariablefonts.sty` 以了解更多詳情。

## 專案 2：使用可變字型示範 LaTeX 的字型選擇指令

* 開啟 Overleaf 專案： <https://www.overleaf.com/1941895198cqjzyhzvxhwz#794ae2>

本專案配置了多種 LaTeX 字型寬度、字重與字形的組合，適用於 Noto Serif、Noto Sans 和 Roboto Mono。它示範如何使用 LaTeX 的字型選擇指令來搭配這些字型 `\fontseries`, `\fontshape` 以及 `\fontfamily`.

![顯示使用 LaTeX 的 \fontseries 指令來排版可變字型的圖片](/files/33a67edb060716fdbc510c1f77699d8604af163c)

## 專案 3：搭配 babel 套件，使用可變字型排版阿拉伯文與英文

* 開啟 Overleaf 專案 <https://www.overleaf.com/3933144323kswvxhnqkbcw#097c77>

本專案示範如何設定 OpenType 可變字型以供 [babel 套件](https://ctan.org/pkg/babel?lang=en)。其中包含使用多種阿拉伯文字 OpenType 可變字型來混合排版英文與阿拉伯文的範例：

* [Noto Naskh Arabic](https://fonts.google.com/noto/specimen/Noto+Naskh+Arabic/tester)
* [Noto Nastaliq](https://fonts.google.com/noto/specimen/Noto+Nastaliq+Urdu/tester)
* [Noto Sans Arabic](https://fonts.google.com/noto/specimen/Noto+Sans+Arabic/tester)

本專案示範 fontspec 的 `\addfontfeatures` 指令可如何對 OpenType 可變字型進行暫時變更，包括本專案中使用的阿拉伯文可變字型。

![顯示使用 LaTeX 與 OpenType 可變字型排版的阿拉伯文與英文段落的圖片](/files/8cf6fa86cab9950083c5d8a44e260fc495846130)

**免責聲明**：所有非英文文字及其對應翻譯皆由 ChatGPT 產生。

## 專案 4：展示可變字型的多個範例

* 開啟 Overleaf 專案 <https://www.overleaf.com/2858462957mvthxfmtgxsc#11aac1>

本專案包含多個範例，示範如何使用 fontspec 的 `\addfontfeatures` 指令對可變字型進行暫時調整；例如，暫時改變字型的寬度或字重，以調整排版某些文字所需的空間。以下各節將概述這些範例，並提供背景資訊，協助你充分運用每個範例。

### 範例：調整字型寬度，在既定空間中容納更多文字

本範例使用 fontspec 的 `\addfontfeatures` 指令來說明：在可變字型的寬度上做小幅、幾乎不易察覺的縮減，就能在既定空間中容納更多文字。兩個包含相同文字的 minipage 並排排版，比較未壓縮的 Noto Serif 與寬度軸值減少 4% 的版本。

![顯示可變字型寬度縮減可在既定空間中容納更多文字的圖片](/files/f16bffd61b2806d747bf2780600dc77c64c2aaff)

### 範例：在 fancyvrb 套件中使用可變字型

使用 fontspec 的 `\newfontfamily` 指令，這個範例示範如何使用你選擇的可變字型，在由 `Verbatim` 環境中，該環境由 [`fancyvrb` 套件](https://ctan.org/pkg/fancyvrb?lang=en)套件提供。它也示範如何使用 LaTeX 的 `\fontseries` 來完成的。

![顯示使用可變字型排版的逐字文字圖片](/files/4ddd657db0560c3841cf01f57628ebed9e9b8225)

#### 關於 Verbatim 環境的一些說明

該 `Verbatim` 環境具有以下形式

```latex
\begin{Verbatim}[⟨settings⟩]
⟨input⟩
\end{Verbatim}
```

其中

* 加上 `[⟨settings⟩]` 部分為選用。 `⟨settings⟩` 可以包含參數（鍵值對），讓你設定這個特定 `Verbatim` 環境
* `⟨input⟩` 是你想要排版的文字

A `Verbatim` 環境會停用 LaTeX 的預設文字處理，因此 `⟨input⟩` 文字可以完全依原樣排版，包括空白、LaTeX 指令、特殊字元與換行。

若要格式化 `⟨input⟩` 文字，例如套用粗體或斜體，請使用 `commandchars` 鍵值於 `⟨settings⟩` 區段中的連結。 `commandchars` 指定三個「特殊」字元，這些字元可用於 `⟨input⟩` 來呼叫 LaTeX 巨集，而不是直接排版。為避免錯誤與衝突，請選擇在一般 `⟨input⟩` 文字中不會在其他地方出現的三個字元。

例如，寫成

```latex
\begin{Verbatim}[commandchars=|()]
⟨input⟩
\end{Verbatim}
```

會告訴 `Verbatim` 環境將字元 `|`, `(`，以及 `)` 視為命令字元。若它們出現在 `⟨input⟩` LaTeX 將會按如下方式處理：

* `|` 用來引入 LaTeX 指令——取代一般的 `\\` 字元。
* `(` 以及 `)` 用來界定 LaTeX 指令引數——取代一般的 `{` 以及 `}`

例如，若要將部分 `⟨input⟩` 文字排成粗體，你可以寫成 `|textbf(some text)` 而不是寫成 `\textbf{some text}`.

### 範例：使用不同樣式排版數字

本範例使用 fontspec 的 `\addfontfeatures` 指令可暫時變更用來排版字元 0、1、2、... 9 的樣式，這些字元通常稱為「數字」或「號碼」。排版師與設計師會將這些字元稱為「figure」，本範例即採用此術語。

#### 關於排版與數字樣式的一些說明

隨著時間推移，為數字排版發展出不同樣式，以適用於文件中的各種元素，例如表格、內文或文件標題。這些樣式是根據數字的三個屬性定義：寬度、高度，以及相對於基線的對齊方式。

有兩種樣式是以數字寬度為基礎：

* **比例式**：每個數字的寬度會依其設計而有所不同。
* **tabular**：每個數字都具有相同的寬度。

另有兩種樣式是以數字高度與對齊方式為基礎：

* **等高**：數字位於基線上，其設計特徵不會低於基線。所有數字具有相同高度。
* **舊式**：數字高度會有所變化，而且數字設計的一部分可能會出現在基線下方。

將這些組合起來，就形成下圖所示的四種排版樣式：

![](/files/be09fdb63d3dcad8674261e6af6d54ef5ab012c7)

一個 [Monotype 發表的文章](https://www.monotype.com/resources/expertise/how-use-figure-styles-illustrator) 討論如何使用這些數字樣式。

#### 如何存取這些數字樣式

這些數字樣式是否可用，取決於你用來排版文件的 OpenType 可變或非可變字型。幸運的是，Noto Serif 支援全部四種數字樣式，因此我們可以使用 `\addfontfeatures` 來套用不同的數字樣式，使用 fontspec 的 `Numbers` 鍵值——請注意 `OldStyle`的大小寫。以下表格是所提供的其中一個範例：

![一個表格，顯示用來排版數字的四種樣式：等寬舊式、比例式舊式、等寬等高，以及比例式等高。](/files/b0640be85c75c153d012c95c0489e46a2fa15378)

* 開啟 Overleaf 專案 <https://www.overleaf.com/2858462957mvthxfmtgxsc#11aac1>

## 專案 5：使用可變字型示範 LaTeX 的「虛擬」字形

* 開啟 Overleaf 專案 <https://www.overleaf.com/4719455662kydjkfvdwjpn#2ea0f1>

LaTeX 的「虛擬」字形並不代表實體字型；相反地，它們旨在與 `\fontshape` 搭配使用，以變更目前字形。專案範例示範如何使用這些指令 `\fontshape`, `\textup`, `\textulc`, `\upshape`，以及 `\ulcshape`.


---

# 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/35-overleaf-projects-showing-how-to-use-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.
