> 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/wen-dang-jie-gou/03-cross-referencing-sections-equations-and-floats.md).

# 章节、公式和浮动体的交叉引用

如果你需要在文档中插入对带编号元素的交叉引用（如公式、章节和图），LaTeX 中有命令可以自动完成。这篇文章将解释如何操作。

## 引言

下面你可以看到一个简单示例，展示如何通过图题编号对图进行交叉引用：

```latex
\section{引言} \label{introduction}
这是一段引言，包含一些占位文本。本节稍后会被引用。

\begin{figure}[h]
\centering
\includegraphics[width=0.3\linewidth]{overleaf-logo}
\caption{这张图片将在下文中被引用。}
\label{fig:leaf}
\end{figure}

你可以引用图片；例如，图 \ref{fig:leaf} 显示了 \textit{Overleaf} 标志。
```

![CrossReferencesEx1Overleaf.png](/files/7fb549c6ee9c185a29ea93d7dfed08bdd7b60e08)

命令 `\label{ }` 用于在标题后设置一个标识符，之后在命令中使用 `\ref{ }` 来设置引用。

[在 Overleaf 中打开示例](https://www.overleaf.com/project/new/template/19401?id=65465598\&templateName=Cross+referencing+example\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

## 引用节和章

下面是如何引用一个节的示例

```latex
\section{引言} \label{introduction}
这是一段引言，包含一些占位文本。本节稍后会被引用。

\begin{figure}[h]
\centering
\includegraphics[width=0.3\linewidth]{overleaf-logo}
\caption{这张图片将在下文中被引用。}
\label{fig:leaf}
\end{figure}

你可以引用图片；例如，图 \ref{fig:leaf} 显示了 \textit{Overleaf} 标志。
\vspace{0.5cm}

\section{数学引用} \label{mathrefs}
正如在 \ref{introduction} 节中提到的，文档中不同的元素都可以被引用。
```

![CrossReferencesEx3Overleaf.png](/files/ec97c51a839d2b3d3f214c2b0d3990cd964a8bac)

同样，命令 `\label` 和 `\ref` 用于引用。该 *label* 是在 `\section` 语句之后设置的，即 `\label` 命令应在该节的计数编号生成后添加。这在章、子节和子子节中也同样适用。见 [章节和小节](/latex/zh-cn/wen-dang-jie-gou/01-sections-and-chapters.md).

[在 Overleaf 中打开示例](https://www.overleaf.com/project/new/template/19401?id=65465598\&templateName=Cross+referencing+example\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

## 引用公式、图和表格

在 [引言](#introduction) 前面展示了一个图片引用的示例，下面介绍公式交叉引用。

```latex
\section{数学引用} \label{mathrefs}
正如在 \ref{introduction} 节中提到的，文档中不同的元素都可以被引用。

\subsection{幂级数} \label{subsection}

\begin{equation} \label{eq:1}
\sum_{i=0}^{\infty} a_i x^i
\end{equation}

公式 \ref{eq:1} 是一个典型的幂级数。
```

![CrossReferencesEx2Overleaf.png](/files/b0519866646114a972d6094bab1c49321fe8cdc5)

有关标签和引用的更多、更灵活示例，请参见

* [使用 amsmath 对齐方程](/latex/zh-cn/shu-xue/06-aligning-equations-with-amsmath.md)
* [表格](/latex/zh-cn/tu-biao-he-biao-ge/01-tables.md)
* [插入图片](/latex/zh-cn/geng-duo-zhu-ti/27-inserting-images.md)

[在 Overleaf 中打开示例](https://www.overleaf.com/project/new/template/19401?id=65465598\&templateName=Cross+referencing+example\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

## 引用元素所在页

元素通常通过分配给它们的编号来引用，但如果需要，你也可以插入它们出现的页面。

```latex
\section{数学引用} \label{mathrefs}
正如在 \ref{introduction} 节中提到的，文档中不同的元素都可以被引用。

\subsection{幂级数} \label{subsection}

\begin{equation} \label{eq:1}
\sum_{i=0}^{\infty} a_i x^i
\end{equation}

公式 \ref{eq:1} 是一个典型的幂级数。
\vspace{0.5cm}

%\Blindtext

\section{最后一节}
在第 \pageref{eq:1} 页的子节 \ref{subsection} 中，展示了一个幂级数的示例。
```

![CrossReferencesEx4Overleaf.png](/files/9abc4bc8a847faa181d69c5b295faabaaf0f8fa1)

命令 `\pageref` 将插入该元素所在的页面，其中该元素的 *label* 被使用。以上面的公式 1 为例。此命令可用于本文提到的所有其他带编号元素。

[在 Overleaf 中打开示例](https://www.overleaf.com/project/new/template/19401?id=65465598\&templateName=Cross+referencing+example\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

## 编译包含交叉引用的文档

在 Overleaf 中，交叉引用会立即生效，但在你的本地 LaTeX 发行版中，要使交叉引用正常工作，你必须将文档编译两次。还有一个命令可以自动完成这项工作，以便所有引用都能正常工作。例如，如果你的文档保存为 `main.tex`.

`latexmk -pdf main.tex`

会生成文件 `main.pdf` ，并使所有交叉引用正常工作。要更改输出格式，请使用 `-dvi` 或 `-ps`.

## 进一步阅读

更多信息请参见：

* [在 LaTeX 中创建文档](/latex/zh-cn/latex-ji-chu/01-learn-latex-in-30-minutes.md)
* [数学表达式](/latex/zh-cn/shu-xue/01-mathematical-expressions.md)
* [使用 amsmath 对齐方程](/latex/zh-cn/shu-xue/06-aligning-equations-with-amsmath.md)
* [插入图片](/latex/zh-cn/geng-duo-zhu-ti/27-inserting-images.md)
* [图片和表格的位置](/latex/zh-cn/tu-biao-he-biao-ge/02-positioning-images-and-tables.md)
* [索引](/latex/zh-cn/wen-dang-jie-gou/04-indices.md)
* [术语表](/latex/zh-cn/wen-dang-jie-gou/05-glossaries.md)
* [目录](/latex/zh-cn/wen-dang-jie-gou/02-table-of-contents.md)
* [大型项目中的管理](/latex/zh-cn/wen-dang-jie-gou/07-management-in-a-large-project.md)
* [多文件 LaTeX 项目](/latex/zh-cn/wen-dang-jie-gou/08-multi-file-latex-projects.md)
* [超链接](/latex/zh-cn/wen-dang-jie-gou/09-hyperlinks.md)
* [计数器](/latex/zh-cn/ge-shi-hua/10-counters.md)
* [LaTeX2ε 不那么简短的介绍](http://www.ctan.org/tex-archive/info/lshort/)


---

# 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/wen-dang-jie-gou/03-cross-referencing-sections-equations-and-floats.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.
