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

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

如果你需要在文档中插入对编号元素的交叉引用（如公式、章节和图），LaTeX 中有命令可以自动完成。本文将说明如何实现。

## 引言

下面你可以看到一个简单的示例，图像通过图注编号进行交叉引用：

```latex
\section{Introduction} \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{Introduction} \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{Math references} \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{Math references} \label{mathrefs}
如 \ref{introduction} 节所述，文档中可以引用不同的元素。

\subsection{Powers series} \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-xing-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{Math references} \label{mathrefs}
如 \ref{introduction} 节所述，文档中可以引用不同的元素。

\subsection{Powers series} \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{Last section}
在 \ref{subsection} 小节中，第 \pageref{eq:1} 页展示了一个幂级数的示例。
```

![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-xing-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://ayakaleaf-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.
