> 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/geng-duo-zhu-ti/42-referencing-figures.md).

# 參照圖形

在 LaTeX 中，我們可以 *標籤* 為有編號的實體（章節、公式等）加上標籤，然後使用該 *標籤* 到 *參照* 在其他地方指向它們；同樣的指令也適用於 figure 環境（它們是有編號的）。

## 標籤與參照基礎

```latex
\label{marker}
```

該 *標記* 可以視為我們為想要參照的物件所取的名稱。重要的是要加上 `\label` *之後* 一個有編號的元素，例如 `\section`, `\subsection`, `\caption` 等，否則標籤就不會「連結」到正確的編號或計數器上。

```latex
\ref{marker}
```

這會印出被以下標籤標記之物件所分配的編號： *標記*.

```latex
\pageref{marker}
```

這會印出被以下標籤標記之物件所在的頁碼： *標記* 出現。

## 編譯包含標籤與參照的 LaTeX 文件

該 *標記* 用來標記物件的文字不會在文件中的任何地方顯示，而對它的參照會被替換為適當的數字。如果我們參照一個不存在的標記，LaTeX 仍會成功編譯，但會出現一個關於未定義參照的警告。對未知標記的參照將被替換為 *??*.

在上方包含的 Overleaf 範例中，你可以看到我們成功地在稍後加入對文件中所含圖形的參照。要實現這一點，LaTeX 必須執行兩次——第一次執行會編譯並儲存所有標籤及其位置，第二次執行則會將所有參照替換為適當的數字。因此，我們必須將文件編譯兩次，才能看到正確的輸出。

## 使用有意義的名稱來參照圖形

由於我們可以使用任何字串作為標籤，因此常見的做法是在標籤前加上幾個字母（作為前綴）來表示被標記的是什麼。當文件中參照了許多不同類型的物件時，這就變得很重要，因為記住某個標籤所指的是哪一類物件可能會很有用。此外，這也使得可以使用一個通用字串來參照不同類型的物件。

例如，如果文件包含

* 一個關於各國人口的章節，
* 一個包含人口數字的表格，以及
* 一個包含人口規模長條圖的圖形，

那麼使用「人口」的各種變體來參照它們所有項目可能會很方便。 *人口*。這可以透過使用以下標籤來達成：

* *sec:population* 用於章節，
* *tab:population* 用於表格，以及
* *fig:population* 用於圖形。

以下是一個圖形範例——

```latex
\begin{figure}[h!]
  \includegraphics[scale=1.7]{birds.jpg}
  \caption{這些鳥}
  \label{fig:birds}
\end{figure}
```

再次注意， `\label` 已被給予 *之後* `\caption`.

&#x20;[在 Overleaf 中開啟範例](https://www.overleaf.com/project/new/template/26046?id=111048636\&templateName=Example+to+cross-reference+figures\&latexEngine=pdflatex\&texImage=texlive-full%3A2022.1\&mainFile=)


---

# 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/geng-duo-zhu-ti/42-referencing-figures.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.
