> 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/43-step-7-using-noto-sans-and-roboto-mono-variable-fonts-with-latex.md).

# 步驟 7：在 LaTeX 中使用 Noto Sans 與 Roboto Mono 可變字型

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

在這一步中，我們為 Noto Sans 和 Roboto Mono 設定粗體、斜體與粗斜體字型樣式，並示範如何使用它們來排版小型大寫字體的粗體、斜體與粗斜體。

開啟在第 6 步中設定好的目前 Overleaf 專案。

## 設定 Noto Sans 和 Roboto Mono

我們要為 Noto Sans 和 Roberto Mono 啟用粗體、斜體與粗斜體字型樣式。這些需求已在下表中，使用 LaTeX 的標準字型系列與字形識別碼加以整理。請記得，系列識別碼中的 m 會被省略 *除了* 其中 *兩個* 寬度與字重為 m（中等）。

| **字型描述**          | **系列識別碼** | **字重** | **寬度** | **字形** |
| ----------------- | --------- | ------ | ------ | ------ |
| 粗字重、中等寬度、正常（直立）字形 | b         | b      | m      | n      |
| 中等字重、中等寬度、斜體字形    | m         | m      | m      | 斜      |
| 粗字重、中等寬度、斜體字形     | b         | b      | m      | 斜      |

以下各節將說明如何設定 Noto Sans 和 Roberto Mono，以使用這些字型系列與字形。 [整合起來](#putting-it-all-together) 說明如何使用 `\setsansfont` 以及 `\setmonofont` 命令的動作重新插入到輸入中（作為單一 token 的 list）。

### 為中等與粗體字重選擇一個重量軸值

我們先選擇重量軸值，以定義 Noto Sans 和 Roberto Mono 的中等字重與粗體字重實例（連結到教學章節）。 [Noto Sans 的重量軸](https://fonts.google.com/specimen/Noto+Sans/tester) 範圍為 100 到 900， [Roboto Mono](https://fonts.google.com/specimen/Roboto+Mono/tester) 其範圍為 100 到 700，因此可建議下列字重值：

| **字型名稱**    | **中等字重** | **粗體字重** |
| ----------- | -------- | -------- |
| Noto Sans   | 400      | 600      |
| Roboto Mono | 300      | 550      |

### 為 Noto Sans 和 Roboto Mono 設定中等字重的斜體字型

要加入斜體字型，我們使用 fontspec 的 `ItalicFont` 鍵，其形式為

```
ItalicFont=⟨font name⟩
```

其中 ⟨font name⟩ 是字型名稱，或字型檔案名稱。

Overleaf 專案的 `VariableFonts` 資料夾包含我們需要使用的斜體字型檔案：

* NotoSans-Italic-VariableFont-wdth-wght.ttf
* RobotoMono-VariableFont-wght.ttf

使用這些檔名及上面列出的重量軸值，可以透過以下各節所示的指令加入中等字重斜體。

#### Noto Sans 中等字重直立與斜體字型的設定

對於 Noto Sans，以下程式碼將加入文件前言區（見該節 [整合起來](#putting-it-all-together)).

```latex
\setsansfont{NotoSans-VariableFont-wdth-wght.ttf}[
Weight=400,
ItalicFont=NotoSans-Italic-VariableFont-wdth-wght.ttf
]
```

#### Roboto Mono 中等字重直立與斜體字型的設定

對於 Roboto Mono，以下程式碼將加入文件前言區（見該節 [整合起來](#putting-it-all-together)).

```latex
\setmonofont{RobotoMono-VariableFont-wght.ttf}[
Weight=300,
ItalicFont=RobotoMono-Italic-VariableFont-wght.ttf
]
```

### 為 Noto Sans 和 Roboto Mono 設定粗體與粗斜體

如第 XXX 步（連結）所示，我們會使用 fontspec 的 `FontFace` 鍵來加入粗體字型，其形式如下

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

其中

* `⟨series⟩` 是 LaTeX 的系列識別碼（連結到章節）
* `⟨shape⟩` 是 LaTeX 的字形識別碼（連結到章節）
* `⟨font name⟩` 是字型檔案名稱或字型名稱
* `⟨features⟩` 包含我們用來設定可變字型的設定，例如設定寬度或字重軸的值

#### Noto Sans 粗體與粗斜體字型的設定

對於粗字重、正常（直立）字形，我們有：

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

因此得到

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

對於粗字重、斜體字形：

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

因此得到

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

#### Roboto Mono 粗體與粗斜體字型的設定

對於粗字重、正常（直立）字形，我們有：

* `⟨series⟩` = b
* `⟨shape⟩` = n
* `⟨font name⟩` = RobotoMono-VariableFont-wght.ttf
* `⟨features⟩` = Weight=550

因此得到

```
FontFace = {b}{n}{Font = RobotoMono-VariableFont-wght.ttf, Weight=550}
```

對於粗字重、斜體字形，我們有：

* `⟨series⟩` = b
* `⟨shape⟩` = it
* `⟨font name⟩` = RobotoMono-VariableFont-wght.ttf
* `⟨features⟩` = Weight=550

因此得到

```
FontFace = {b}{it}{Font = RobotoMono-VariableFont-wght.ttf, Weight=550}
```

## 整合起來

要套用上面討論的設定，請開啟目前的 Overleaf 專案，並將現有的 `\setsansfont` 以及 `\setmonofont` 指令替換為以下版本。

```latex
% 文件主體無襯線字型
\setsansfont{NotoSans-VariableFont-wdth-wght.ttf}[
Weight=400,
ItalicFont=NotoSans-Italic-VariableFont-wdth-wght.ttf,
FontFace = {b}{n}{Font = NotoSans-VariableFont-wdth-wght.ttf, Weight=600},
FontFace = {b}{it}{Font =NotoSans-Italic-VariableFont-wdth-wght.ttf,Weight=600}
]
```

```latex
% 文件主體等寬字型
\setmonofont{RobotoMono-VariableFont-wght.ttf}[
Weight=400,
ItalicFont=RobotoMono-Italic-VariableFont-wght.ttf,
FontFace = {b}{n}{Font =RobotoMono-VariableFont-wght.ttf, Weight=550},
FontFace = {b}{it}{Font = RobotoMono-Italic-VariableFont-wght.ttf, Weight=550}
]
```

## 如何使用我們的新字型

使用 fontspec，我們已為文件的三種字型家族都設定了粗體、斜體與粗斜體字型。除了已設定的字型之外，fontspec 也啟用了小型大寫字型版本，只要將以下程式碼貼入文件中（在 \begin{document} 之後）即可看見：

```latex
\begin{itemize}
\item 主本文字家族（Noto Serif）：
\begin{itemize}
    \item \textsc{常規小型大寫}
    \item \textit{\scshape 斜體小型大寫}  
    \item \textbf{\scshape 粗體小型大寫}
    \item \textbf{\itshape\scshape 粗斜體小型大寫}
\end{itemize}
\item 無襯線字型家族（Noto Sans）：
\begin{itemize}
    \item \textsc{\sffamily 常規小型大寫}
    \item \textit{\sffamily\scshape 斜體小型大寫}  
    \item \textbf{\sffamily\scshape 粗體小型大寫}
    \item \textbf{\sffamily\itshape\scshape 粗斜體小型大寫}
\end{itemize}
\item 等寬字型家族（Roboto Mono）：
\begin{itemize}
    \item \textsc{\ttfamily 常規小型大寫}
    \item \textit{\ttfamily\scshape 斜體小型大寫}  
    \item \textbf{\ttfamily\scshape 粗體小型大寫}
    \item \textbf{\ttfamily\itshape\scshape 粗斜體小型大寫}
\end{itemize}
```

這段程式碼會產生以下輸出

![顯示使用三種文件字型家族，以正常、粗體與粗斜體排版的小型大寫字型圖片。](/files/2f01bc72f99e04effc84f5c93c50d10ec53488f6)

## 下一步

我們專案文件的前言區現在因為大量 fontspec 設定程式碼而相當雜亂。在第 8 步中，我們會把 fontspec 設定程式碼移到一個簡單的專案中，藉此簡化文件前言區，並讓更新字型變得更容易。


---

# 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/43-step-7-using-noto-sans-and-roboto-mono-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.
