> 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/37-step-1-setting-up-an-overleaf-project-to-use-variable-fonts.md).

# 步驟 1：設定 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 專案](https://www.overleaf.com/8438931911svtqtnmfvsrp#28008d) 其中包含以下可變字型：

* [Noto Serif](https://fonts.google.com/noto/specimen/Noto+Serif/tester) （主文件文字）
* [Noto Sans](https://fonts.google.com/noto/specimen/Noto+Sans/tester) （無襯線字型）
* [Roboto Mono](https://fonts.google.com/specimen/Roboto+Mono/tester) （等寬字型）

這些字型尚未設定好可供使用。起初，當你編譯 [隨附的 Overleaf 專案](https://www.overleaf.com/8438931911svtqtnmfvsrp#28008d)時，LaTeX 的標準（預設）文字字型將會套用。整個教學過程中，你將學習如何將這些預設字型替換為專案資料夾中提供的可變字型，該資料夾名為 `VariableFonts`.

如果你偏好使用不同的可變字型，只要依照以下說明操作即可。否則，請繼續進行到 [步驟 2](https://www.overleaf.com/learn/latex/Articles/Step_2:_An_introduction_to_LaTeX_fonts?preview=true) 本教學。

## （選用）如何選擇並上傳你自己的可變字型

依照以下步驟上傳你選擇的可變字型。

### 1. 從 Google Fonts 取得可變字型

[Google Fonts](https://fonts.google.com/) 是一個極佳的資源。它提供 [實用文件](https://fonts.google.com/knowledge/introducing_type/introducing_variable_fonts) 以及許多 [可免費使用的可變字型](https://fonts.google.com/?vfonly=true) 可上傳至 Overleaf，並在你的專案中設定使用。

* **提示**：使用 Google Fonts 的篩選器來尋找可變字型。將 *Technology* 篩選條件設為 *Variable* 以僅顯示可變字型。可使用其他篩選條件，例如 *Serif*，以進一步縮小搜尋結果。

![顯示 Google Fonts 搜尋篩選條件的圖片](/files/1b137f9a19dcf5bff8605ddacab8af426b34b9c9)

* **提示**：你可以依據可變字型所支援的設計軸瀏覽字型：請參閱 <https://fonts.google.com/variablefonts>。Google 也提供可變字型設計軸的定義：請參閱 <https://fonts.google.com/variablefonts#axis-definitions>.
* 找到你想使用的可變字型後，請將它們下載到本機裝置，並將包含有問題字元的檔案重新命名。
* 有些可變字型由兩個 `.ttf` 檔案組成：一個是正立（一般）字形，若有提供，另一個是斜體字形。請務必對你下載的每一個字型確認這一點。

### 2. 重新命名有問題的 Google 字型檔案名稱

Google 對可變字型檔案的命名方式會包含字型的設計軸，並以逗號分隔。不幸的是，這種命名方式會讓 fontspec 出現問題；fontspec 是在 LuaLaTeX 中使用可變字型所必需的套件。例如，Noto Serif 提供寬度與字重兩個軸，並以兩個檔案提供——一個是正立字型，另一個是斜體字型：

* NotoSerif-VariableFont\_wdth,wght.ttf
* NotoSerif-Italic-VariableFont\_wdth,wght.ttf

這些檔案名稱中的逗號在 fontspec 的 `\setmainfont` 指令中使用時會觸發錯誤。例如，寫入

```
\setmainfont{NotoSerif-VariableFont_wdth,wght.ttf}
[ItalicFont = NotoSerif-Italic-VariableFont_wdth,wght.ttf]
```

會產生包含以下內容的錯誤：

```
! 套件 fontspec 錯誤：字型 "NotoSerif-Italic-VariableFont_wdth" 無法
（fontspec）                找不到。

! LaTeX 錯誤：鍵值 'fontspec-opentype/wght.ttf' 未知，並且已被
（LaTeX）        忽略。
```

若要解決這個問題，你需要重新命名字型檔案，移除逗號（以及底線 '\_'），並以「安全」字元取代，例如連字號（'-'），而且不要加入空格字元。例如，你可以將下列檔案重新命名：

* NotoSans-VariableFont\_wdth,wght.ttf

改為

* NotoSans-VariableFont-wdth-wght.ttf

這個簡單的重新命名步驟有助於避免衝突，並確保可變字型能順利整合到你的 LaTeX 文件中。

### 3. 建立新的 Overleaf 專案

* 建立新的 Overleaf 專案，並 [將編譯器設定為 LuaLaTeX](/latex/zh-tw/zhi-shi-ku/026-changing-compiler.md) ，因為它是唯一支援可變字型的編譯器。
* 將 `fontspec` 套件加入你的文件前言，寫入 `\usepackage{fontspec}`.
* 選取檔案上傳圖示（![Image displaying Overleaf file-upload icon](/files/edbfa8b45eb08a8627449224557bd36047e8c4b4)）以將本機重新命名的可變字型檔案加入你的新專案：

![顯示如何將檔案上傳至 Overleaf 專案的圖片](/files/9eaf5fdd8f9693506319310f97a7f673188ee05a)

### 4.（選用）整理專案的字型檔案

如果你想嘗試多種字型，例如在測試文件設計時，使用專案資料夾來整理字型檔案會很有幫助。然而，在編譯時，LaTeX 不會自動在你的專案資料夾中搜尋字型；你需要透過名為 [latexmkrc](/latex/zh-tw/shen-ru-wen-zhang/28-how-to-use-latexmkrc-with-overleaf.md)的本機設定檔來協助 LaTeX。我們在此不深入說明，但建議建立一個名為 `VariableFonts` 並複製 `latexmkrc` 在 [隨附專案](https://www.overleaf.com/8438931911svtqtnmfvsrp#28008d).

## 在下一步

第 2 步介紹了 LaTeX 的字型選擇模型：新字型選擇方案，並提供本教學其餘部分所使用的重要背景資訊。

[簡介](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-tw/shen-ru-wen-zhang/37-step-1-setting-up-an-overleaf-project-to-use-variable-fonts.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.
