> 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-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 必须运行两次——第一次运行会编译并保存所有标签及其位置，第二次运行时所有引用都会被替换为相应的编号。因此，我们必须将文档编译两次才能看到正确的输出。

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

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

例如，如果文档包含

* 一个关于各国人口的章节，
* 一张包含人口数字的表格，以及
* 一幅包含人口规模柱状图的图形，

使用以下词的变体来指代它们所有内容可能会更方便： *人口*。这可以通过使用如下标签来实现：

* *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-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.
