> For the complete documentation index, see [llms.txt](https://ayakaleaf-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://ayakaleaf-pro.ayaka.space/latex/zh-cn/geng-duo-zhu-ti/42-referencing-figures.md).

# 引用图形

在 LaTeX 中，我们可以 *label* 对有编号的实体（章节、公式等）进行标记，然后使用该 *label* 更改为 *引用* 在其他地方引用它们，而且同样的命令也适用于 figure 环境（它们也是有编号的）。

## 标签与引用基础

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

该 *标记* 可以看作是我们赋给想要引用的对象的名称。重要的是要添加 `\label` *在* 一个有编号的元素，例如 `\section`, `\subsection`, `\caption` 等等，否则标签就不会“绑定”到正确的编号或计数器上。

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

这会打印出由其标记的对象的编号 *标记*.

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

这会打印出由其标记的对象所在页的页码 *标记* 出现。

## 编译带有标签和引用的 LaTeX 文档

该 *标记* 用于给对象加标签的内容不会显示在文档中的任何地方，而对它的引用会被替换为相应的数字。如果我们引用一个不存在的标记，LaTeX 仍会成功编译，但会发出关于未定义引用的警告。对未知标记的引用将被替换为 *??*.

在上面包含的 Overleaf 示例中，你可以看到我们成功地为文档中后续加入的图形添加了引用。为此，LaTeX 必须运行两次——第一次运行会编译并保存所有标签及其位置，第二次运行则会将所有引用替换为相应的编号。因此，我们必须将文档编译两次才能看到正确的输出。

## 使用有意义的名称来引用图形

由于我们可以使用任意字符串作为标签，因此通常会在标签前加上几个字母（作为前缀）来表明被标记的是什么。当文档中引用了很多不同类型的对象时，这一点就很重要，因为记住某个标签所指的对象类型会很有用。此外，这也使得可以使用一个通用字符串来引用不同类型的对象。

例如，如果一份文档包含

* 一个关于国家人口的章节，
* 一个包含人口数值的表格，以及
* 一个包含人口规模柱状图的图，

那么使用以下内容的变体来引用它们可能会更方便： *population*。这可以通过使用以下标签来实现

* *sec:population* 用于该章节，
* *tab:population* 用于该表格，以及
* *fig:population* 用于该图。

下面是图的一个示例——

```latex
\begin{figure}[h!]
  \includegraphics[scale=1.7]{birds.jpg}
  \caption{The birds}
  \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://ayakaleaf-pro.ayaka.space/latex/zh-cn/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.
