> 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/wen-shu-gou-zao/09-hyperlinks.md).

# ハイパーリンク

LaTeX は、印刷可能でプロフェッショナルな見た目の文書を作成するのに優れたツールですが、優れたナビゲーション機能を備えた PDF ファイルを生成するためにも使えます。この記事では、文書内にハイパーリンクを作成する方法と、PDF リーダーで表示できるように LaTeX 文書を設定する方法を説明します。

## はじめに

まずは、単に次のものを読み込むだけの最小限の動作例から始めましょう。 **hyperref** all パッケージ [相互参照された要素](/latex/ja/wen-shu-gou-zao/03-cross-referencing-sections-equations-and-floats.md) がハイパーリンクになります。

```latex
\documentclass{book}
\usepackage{blindtext}
\usepackage{hyperref}

\title{ハイパーリンクの例}
\author{Overleaf}

\begin{document}

\frontmatter
\tableofcontents
\clearpage

\addcontentsline{toc}{chapter}{序文}
{\huge {\bf まえがき}}

\Blindtext
\clearpage

\addcontentsline{toc}{chapter}{ダミー項目}
{\huge {\bf ダミー項目}}

\Blindtext
\mainmatter

\chapter{第1章}

ここは空の章になります

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

式 \ref{eq:1} は、収束しない和を示しています。この式は後で \pageref{second} ページで使われます。

\Blindtext
\clearpage

\section{第2節} \label{second}

\blindtext
\Blinddocument
\end{document}
```

[この `hyperref` Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Basic+hyperref+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cusepackage%7Bhyperref%7D%0A%0A%5Ctitle%7BExample+of+Hyperlinks%7D%0A%5Cauthor%7BOverleaf%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cfrontmatter%0A%5Ctableofcontents%0A%5Cclearpage%0A%0A%5Caddcontentsline%7Btoc%7D%7Bchapter%7D%7BForeword%7D%0A%7B%5Chuge+%7B%5Cbf+Foreword%7D%7D%0A%0A%5CBlindtext%0A%5Cclearpage%0A%0A%5Caddcontentsline%7Btoc%7D%7Bchapter%7D%7BDummy+entry%7D%0A%7B%5Chuge+%7B%5Cbf+Dummy+entry%7D%7D%0A%0A%5CBlindtext%0A%5Cmainmatter%0A%0A%5Cchapter%7BFirst+Chapter%7D%0A%0AThis+will+be+an+empty+chapter%0A%0A%5Cbegin%7Bequation%7D%0A%5Clabel%7Beq%3A1%7D%0A%5Csum_%7Bi%3D0%7D%5E%7B%5Cinfty%7D+a_i+x%5Ei%0A%5Cend%7Bequation%7D%0A%0AThe+equation+%5Cref%7Beq%3A1%7D+shows+a+sum+that+is+divergent.+This+formula+will+be+used+later+on+page+%5Cpageref%7Bsecond%7D.%0A%0A%5CBlindtext%0A%5Cclearpage%0A%0A%5Csection%7BSecond+section%7D+%5Clabel%7Bsecond%7D%0A%0A%5Cblindtext%0A%5CBlinddocument%0A%5Cend%7Bdocument%7D)

![hyperref の文書例](/files/e8f216d63ef387bfd8d60f4c0265db3394b1bcce)

目次の各行は、文書のプリアンブルに次の行を追加するだけで、文書内の対応するページへのリンクになります

```latex
\usepackage{hyperref}
```

読み込む際には注意が必要です `hyperref`。通常、これは最後に読み込まれるパッケージでなければなりませんが、この規則には例外があるかもしれません。

## スタイルと色

リンクの既定の書式は変更できるため、文書内の情報をより明確に表示できます。以下に例を示します：

```latex
\documentclass{book}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
    pdftitle={Overleaf Example},
    pdfpagemode=FullScreen,
    }

\urlstyle{same}

\begin{document}

\tableofcontents

\chapter{第1章}

ここは空の章になり、ここに少し文章を入れます

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

式 \ref{eq:1} は、収束しない和を示しています。この式は
後で \pageref{second} ページで使われます。

さらに参照するには \href{http://www.overleaf.com}{何か
のリンク} または次の URL: \url{http://www.overleaf.com} または開く
次のファイル \href{run:./file.txt}{File.txt}

任意の単語に直接リンクを張ることもできます
\hyperlink{thesentence}{任意の文} にも。

\end{document}
```

[Overleafで `hyperref` パッケージの例を開く](https://www.overleaf.com/project/new/template/19606?id=64789057\&templateName=Another+hyperref+example\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=main.tex)

![HyperrefEx2OverleafVa.png](/files/445f9963195f2b31ddb3879802033fbdf63c228e)

![HyperrefEx2OverleafVb.png](/files/209951a2e565a16fd1d1a4751ade8ab296b9aef3)

これは完全な例で、記事の残りの部分で詳しく説明します。以下に、リンクの色とスタイルに関するコマンドの説明を示します。

**\hypersetup{ ... }**

これは、文書内のリンクの動作を設定するためのオプションを指定します。各パラメータはカンマで区切り、構文は parameter=value の形式でなければなりません。

**colorlinks=true**

リンクに色が付けられ、既定の色は赤です。

**linkcolor=blue**

相互参照された要素によって生成される内部リンクは青で表示されます。

**filecolor=magenta**

ローカルファイルへのリンクはマゼンタ色で表示されます（ローカルファイルへのリンクを参照）。

**urlcolor=cyan**

Web サイトへのリンクはシアン色に設定されます（Web アドレスへのリンクを参照）。

**urlstyle{same}**

既定の設定ではリンクは等幅系のスペース付きフォントで表示されますが、このコマンドはそれを変更し、リンクを本文と同じスタイルで表示します。

## Web アドレスへのリンク

Web アドレスやメールへのリンクは、LaTeX ファイルに次の `\url` コマンドを使って実際のリンクを表示するか、 `\href` を使って非表示のリンクを作成し、代わりに単語や文を表示できます。

```latex
さらに参照するには \href{http://www.overleaf.com}{何かのリンク}
または次の URL: \url{http://www.overleaf.com}
```

![HyperlinkExampleUpdatedMore.png](/files/9ba3529ad4174c289c2f45cbe268902dbfb9ba71)

この例には、最終的な文書でリンクを生成するコマンドが 2 つあります：

**\href{<http://www.overleaf.com}{何かのリンク}>**

このコマンドには 2 つの引数が渡されます。1 つ目はリンク先の URL で、この場合は <http://www.overleaf.com> です。2 つ目はクリック可能な表示テキストで、何かのリンク です。

**\url{<http://www.overleaf.com}>**

このコマンドは、引数として渡された URL を表示し、それをリンクにします。文書を印刷する場合に便利です。

[Overleaf で hyperref パッケージの例を開く](https://www.overleaf.com/project/new/template/19606?id=64789057\&templateName=Hyperref+Example+2\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=main.tex)

## ローカルファイルへのリンク

コマンド `\href` や `\url` 前の節で紹介したものは、ローカルファイルを開くために使えます

```latex
さらに参照するには \href{http://www.overleaf.com}{何かのリンク}
または次の URL: \url{http://www.overleaf.com} または次の
ファイル \href{run:./file.txt}{File.txt}
```

![HyperlinkExampleUpdatedMoreNext.png](/files/d3a51023c613c469fc09fdbd331fa3a5b08e59f6)

コマンド `\href{run:./file.txt}{File.txt}` 次のテキストを表示します `File.txt` これは次の名前のローカルファイルへのリンクです `file.txt` 現在の作業ディレクトリにあります。テキストに注目してください `run:` をファイルへのパスの前に付けます。

ファイルパスは UNIX 系システムの規則に従っており、 `.` は現在のディレクトリを示し、 `..` は一つ上のディレクトリを示します。

コマンド `\url{}` も、パスについて説明したのと同じ構文で使用できますが、いくつか問題があると報告されています。

[Overleaf で hyperref パッケージの例を開く](https://www.overleaf.com/project/new/template/19606?id=64789057\&templateName=Hyperref+Example+2\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=main.tex)

## リンクを手動で挿入する

前に述べたように、相互参照された要素は、いったん **hyperref** が読み込まれると、したがって次を使えます `\label` 文書のどこでも使えて、後でそのラベルを参照してリンクを作成できます。ハイパーリンクを手動で挿入する方法はこれだけではありません。

```latex
任意の単語に直接リンクを張ることもできます
あるいは文書内の \hyperlink{thesentence}{任意の文} にも。

このテキストを読んでも、得られる情報はありません。本当に？
本当に情報はないのでしょうか？

たとえば \hypertarget{thesentence}{この文} です。
```

![HyperlinkExampleUpdatedMoreNextAgain.png](/files/f2e04388d3f92fffc23369e7bae33b93d05debe3)

ユーザー定義のリンクを作成するコマンドは 2 つあります。

**\hypertarget{thesentence}{この文}**

このコマンドに波括弧内で渡す 1 つ目の引数は、この文の一意な識別子です。2 つ目の引数はテキスト「この文」で、通常どおり表示されます（anchorcolor の値によります。参考ガイドを参照してください）。ただし、識別子「thesentence」を指すリンクをクリックすると、PDF ファイルはこの位置までスクロールします。

**\hyperlink{thesentence}{任意の文}**

このコマンドは、「任意の文」というテキストを、識別子が「thesentence」の場所へ移動するクリック可能な要素として表示します。

[Overleaf で hyperref パッケージの例を開く](https://www.overleaf.com/project/new/template/19606?id=64789057\&templateName=Hyperref+Example+2\&latexEngine=pdflatex\&texImage=\&mainFile=main.tex)

## PDF 固有のオプション

文書内のリンクは、PDF 形式で読む文書を想定して作成されます。PDF ファイルは、さらにカスタマイズして追加情報を加えたり、PDF ビューアでの表示方法を変更したりできます。以下に例を示します：

```latex
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
    pdftitle={Overleaf Example},
    pdfpagemode=FullScreen,
}
```

![Pdftitle.png](/files/89a2b3fba501078519f2408e9291e9f54b431803)

コマンドを使用して `\hypersetup`、第 [スタイルと色](#styles-and-colours)で説明したとおり、最終的な PDF ファイルを設定するための追加パラメータを受け付けます。

**pdftitle={Overleaf の例}**

PDF 出力ファイルのタイトルで、ウィンドウのタイトルバーに表示されます。例では「Overleaf の例」です。

**pdfpagemode=FullScreen**

文書は PDF リーダーで全画面モードで開かれます。

次を参照してください [リファレンスガイド](#reference-guide) 渡せるオプションの完全な一覧は `\hypersetup`.

[Overleaf で hyperref パッケージの例を開く](https://www.overleaf.com/project/new/template/19606?id=64789057\&templateName=Hyperref+Example+2\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=main.tex)

## リファレンスガイド

**リンクのスタイルオプション**

| オプション         | 既定値     | 説明                                     |
| ------------- | ------- | -------------------------------------- |
| `hyperindex`  | true    | 索引項目のページ番号をハイパーリンクにします                 |
| `linktocpage` | false   | 目次では、テキストではなくページ番号をリンクにします。            |
| `breaklinks`  | false   | リンクを複数行に折り返せるようにします。                   |
| `colorlinks`  | false   | リンクとアンカーのテキストに色を付けます。これらの色は印刷版にも表示されます |
| `linkcolor`   | red     | 通常の内部リンクの色                             |
| `anchorcolor` | black   | アンカー（ターゲット）テキストの色                      |
| `citecolor`   | green   | 文献引用の色                                 |
| `filecolor`   | cyan    | ローカルファイルを開くリンクの色                       |
| `urlcolor`    | magenta | リンクされた URL の色                          |
| `frenchlinks` | false   | リンクでは色の代わりにスモールキャップを使います               |

**PDF 固有のオプション**

| オプション             | 既定値     | 説明                                                                       |
| ----------------- | ------- | ------------------------------------------------------------------------ |
| `bookmarks`       | true    | 目次と同様に、Acrobat のブックマークが書き込まれます。                                          |
| `bookmarksopen`   | false   | ブックマークはすべてのサブツリーを展開した状態で表示されます。                                          |
| `citebordercolor` | 0 1 0   | RGB 形式での引用の周囲の枠の色。                                                       |
| `filebordercolor` | 0 .5 .5 | RGB 形式でのファイルリンクの周囲の枠の色。                                                  |
| `linkbordercolor` | 1 0 0   | RGB 形式での通常のリンクの周囲の枠の色。                                                   |
| `menubordercolor` | 1 0 0   | RGB 形式でのメニューリンクの周囲の枠の色。                                                  |
| `urlbordercolor`  | 0 1 1   | RGB 形式での URL リンクの周囲の枠の色。                                                 |
| `pdfpagemode`     | 空       | ファイルの開き方を決定します。可能な値は UseThumbs（サムネイル）、UseOutlines（ブックマーク）、FullScreen です。 |
| `pdftitle`        |         | 文書のタイトルを設定します。                                                           |
| `pdfauthor`       |         | 文書の著者を設定します。                                                             |
| `pdfstartpage`    | 1       | PDF ファイルをどのページで開くかを決定します。                                                |

## さらに読む

詳細については

* [目次](/latex/ja/wen-shu-gou-zao/02-table-of-contents.md)
* [セクションと章](/latex/ja/wen-shu-gou-zao/01-sections-and-chapters.md)
* [節や数式の相互参照](/latex/ja/wen-shu-gou-zao/03-cross-referencing-sections-equations-and-floats.md)
* [LaTeXで色を使う](/latex/ja/shu-shi-she-ding/13-using-colors-in-latex.md)
* [大規模プロジェクトでの管理](/latex/ja/wen-shu-gou-zao/07-management-in-a-large-project.md)
* [Hyperref マニュアル](http://repositorios.cpai.unb.br/ctan/macros/latex/contrib/hyperref/doc/manual.pdf)
* [Wikibooks のハイパーリンクに関する記事](http://en.wikibooks.org/wiki/LaTeX/Hyperlinks)


---

# 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/wen-shu-gou-zao/09-hyperlinks.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.
