> 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/wen-jian-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/903a76278bf88ac5659d277cac64b193bd968945)

命令 `\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/7779241e477c2b9c35cf6e795fc0643f8a9fe822)

同樣地，這些指令 `\label` 和 `\\ref` 可用於參照。 *label* 會在 `\section` 敘述之後設定，也就是 `\label` 在章節的計數編號產生後，應將指令加在其後。這也適用於章、子節與次子節。請參見 [章節](/latex/zh-tw/wen-jian-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/01ea9e3e4c65a45e3ac1455cd53526af10dc6604)

如需更多且更具彈性的標籤與參照範例，請參見

* [使用 amsmath 對齊方程式](/latex/zh-tw/shu-xue/06-aligning-equations-with-amsmath.md)
* [表格](/latex/zh-tw/tu-biao-yu-biao-ge/01-tables.md)
* [插入圖片](/latex/zh-tw/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{最後一節}
在小節 \ref{subsection} 中，第 \pageref{eq:1} 頁展示了一個冪級數的範例。
```

![CrossReferencesEx4Overleaf.png](/files/7f630a4ae196adcef8162dbb6a3da3f078ee55f8)

命令 `\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-tw/latex-ji-chu/01-learn-latex-in-30-minutes.md)
* [數學表達式](/latex/zh-tw/shu-xue/01-mathematical-expressions.md)
* [使用 amsmath 對齊方程式](/latex/zh-tw/shu-xue/06-aligning-equations-with-amsmath.md)
* [插入圖片](/latex/zh-tw/geng-duo-zhu-ti/27-inserting-images.md)
* [圖片與表格的定位](/latex/zh-tw/tu-biao-yu-biao-ge/02-positioning-images-and-tables.md)
* [索引](/latex/zh-tw/wen-jian-jie-gou/04-indices.md)
* [詞彙表](/latex/zh-tw/wen-jian-jie-gou/05-glossaries.md)
* [目錄](/latex/zh-tw/wen-jian-jie-gou/02-table-of-contents.md)
* [大型專案中的管理](/latex/zh-tw/wen-jian-jie-gou/07-management-in-a-large-project.md)
* [多檔案 LaTeX 專案](/latex/zh-tw/wen-jian-jie-gou/08-multi-file-latex-projects.md)
* [超連結](/latex/zh-tw/wen-jian-jie-gou/09-hyperlinks.md)
* [計數器](/latex/zh-tw/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-tw/wen-jian-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.
