> 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/ja/sononotopikku/42-referencing-figures.md).

# 図の参照

LaTeXでは、私たちは *ラベルを付ける* 番号が付いた要素（節、数式など）に対して、それを使って *ラベルを付ける* に *参照する* それらを別の場所で参照でき、同じコマンドは図環境にも適用できます（こちらも番号が付いています）。

## ラベルと参照の基本

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

その *マーカー* は、参照したいオブジェクトに付ける名前と考えられます。追加することが重要です `\label` *の後に* 番号付き要素の後に、たとえば `\section`, `\subsection`, `\caption` などを置きます。そうしないと、ラベルが正しい番号やカウンターに「紐づきません」。

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

これは、〜でラベル付けされたオブジェクトに割り当てられた番号を表示します *マーカー*.

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

これは、〜でラベル付けされたオブジェクトが *マーカー* 現れるページ番号を表示します。

## ラベルと参照を含むLaTeX文書のコンパイル

その *マーカー* オブジェクトのラベル付けに使ったものは文書中のどこにも表示されず、それへの参照は適切な番号に置き換えられます。存在しないマーカーを参照すると、LaTeXは警告付きで未定義の参照としてコンパイルは成功しますが、未知のマーカーへの参照は *??*.

上に示したOverleafの例では、文書に後から追加した図にも参照を正しく付けられることが分かります。これを可能にするには、LaTeXを2回実行する必要があります。1回目の実行で、すべてのラベルとその位置をコンパイルして保存し、2回目の実行で、すべての参照が適切な番号に置き換えられます。したがって、正しい出力を見るには文書を2回コンパイルしなければなりません。

## 図を参照するために意味のある名前を使う

ラベルには任意の文字列を使えるため、何をラベル付けしているのかを示すために、ラベルの先頭にいくつかの文字を付ける（接頭辞として）のが一般的です。文書内でさまざまな種類のオブジェクトを多く参照する場合には、ラベルがどの種類のオブジェクトを指しているかを覚えやすくなるので重要です。さらに、共通の文字列を使って異なる種類のオブジェクトを参照することもできます。

たとえば、文書に次のものが含まれている場合

* 各国の人口に関する節、
* 人口数を含む表、そして
* 人口規模の棒グラフを含む図があるとすると、

それらすべてを〜の変形を使って参照すると便利かもしれません *population*。これは次のラベルを使うことで実現できます

* *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/ja/sononotopikku/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.
