> 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/04-indices.md).

# 索引

大きな文書、たとえば本では、主要な用語を含むアルファベット順の一覧を作るのが慣例です。LaTeX と補助プログラム **imakeidx**、を使えば、索引はかなり簡単に生成できます。

## はじめに

簡単な動作例を見てみましょう。

```latex
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{imakeidx}
\makeindex

\begin{document}
\section{導入}
この例では、いくつかのキーワード\index{keywords}を使います
これらは重要で、索引\index{Index} に載る価値があります。

generate\index{generate} や some\index{others} のような用語も
現れます。

\printindex
\end{document}
```

[Overleaf でこの例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Index+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5BT1%5D%7Bfontenc%7D%0A%5Cusepackage%7Bimakeidx%7D%0A%5Cmakeindex%0A%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BIntroduction%7D%0AIn+this+example%2C+several+keywords%5Cindex%7Bkeywords%7D+will+be+used+%0Awhich+are+important+and+deserve+to+appear+in+the+Index%5Cindex%7BIndex%7D.%0A%0ATerms+like+generate%5Cindex%7Bgenerate%7D+and+some%5Cindex%7Bothers%7D+will+%0Aalso+show+up.+%0A%0A%5Cprintindex%0A%5Cend%7Bdocument%7D)

次の画像は、上の例によって生成された出力を示しています：

![Index1OLV2.png](/files/1786a0511a50f78cfe149b27b4ae8d1213b15c61)

まず、パッケージはプリアンブルで次の行によって読み込まれます

```latex
\usepackage{imakeidx}
```

次にコマンド `\makeindex` は索引を機能させるために必須であり、見た目を調整するためのいくつかのパラメータを取ることができます。次の節でそれが明らかになります。

索引に項目を追加するにはコマンド `\index{}` を使います。追加したい単語をパラメータとして入れます。注意してください。これは現在の位置にその単語を印字するのではなく、索引にのみ表示します。

最後に、コマンド `\printindex` が実際に索引を出力します。 `babel` パッケージを使って特別なローカライズをしている場合、タイトルはそれに応じて翻訳されます。

注:  `imakeidx`、の代わりに、パッケージ `makeidx` を読み込むこともできますが、カスタマイズの自由度は低くなります。

## Overleaf の索引

Overleaf のプロジェクトに索引を追加する場合、 **重要なのは** 、索引を正しくコンパイルするために、メイン `.tex` ファイルがプロジェクトのルートディレクトリにある必要があり、 *どのフォルダの外にも置かなければならないことです*。これにより、索引生成に必要な補助ファイルが、コンパイラからアクセスできる形でキャッシュされます。

## 項目とサブ項目

前の節で述べたように、コマンド `\index` は、渡された単語を索引に追加しますが、それだけが使い方ではありません。

```latex
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{imakeidx}
\makeindex

\begin{document}
\section{導入}
この例では、いくつかのキーワード\index{keywords}を使います
これらは重要で、索引\index{Index} に載る価値があります。

generate\index{generate} や some\index{others} のような用語も
現れます。索引の項目は入れ子にもできます \index{Index!nested}

\clearpage

\section{第2節}
この第2の節\index{section} には何らかの特別な語が含まれているかもしれません
また、すでに使われているものを拡張できます\index{keywords!used}。

\printindex
\end{document}
```

[Overleaf でこの例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Index+example+2\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5BT1%5D%7Bfontenc%7D%0A%5Cusepackage%7Bimakeidx%7D%0A%5Cmakeindex%0A%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BIntroduction%7D%0AIn+this+example%2C+several+keywords%5Cindex%7Bkeywords%7D+will+be+used+%0Awhich+are+important+and+deserve+to+appear+in+the+Index%5Cindex%7BIndex%7D.%0A%0ATerms+like+generate%5Cindex%7Bgenerate%7D+and+some%5Cindex%7Bothers%7D+will+also+%0Ashow+up.+Terms+in+the+index+can+also+be+nested+%5Cindex%7BIndex%21nested%7D%0A%0A%5Cclearpage%0A%0A%5Csection%7BSecond+section%7D%0AThis+second+section%5Cindex%7Bsection%7D+may+include+some+special+word%2C+%0Aand+expand+the+ones+already+used%5Cindex%7Bkeywords%21used%7D.%0A%0A%5Cprintindex%0A%5Cend%7Bdocument%7D)

次の画像は、上の例によって生成された出力を示しています：

![Index2OLV2.png](/files/0c1687b7bef2f30632c8d31ce244816f3c4786ca)

索引の用語に特別な形容詞を含めて拡張するのは一般的な慣習です。たとえば、 *体* は、形容詞 *有限* が前に付くか、あるいは *標数 0 の*が後ろに付くと特別な意味を持つことがあります。また、異なる種類の *体*ものを索引に別々の項目として追加するのは少し面倒です。そのような場合は、感嘆符「!」を追加すると、この記号の後ろの用語が主要語 *体*.

のサブ項目として追加されます。例では、「Index」という語にサブ項目として「nested」があります。

## 索引の書式設定

索引タイトルの変更、複数列の追加、列幅の変更などの簡単な書式設定は、 `\makeindex`:

```latex
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{imakeidx}
\makeindex[columns=3, title=アルファベット順索引]

\begin{document}
\section{導入}
この例では、いくつかのキーワード\index{keywords}が使われます。これらは
重要で、索引\index{Index} に載る価値があります。

generate\index{generate} や some\index{others} のような用語も
現れます。索引の項目は入れ子にもできます \index{Index!nested}

\clearpage

\section{第2節}
この第2の節\index{section} には何らかの特別な語が含まれているかもしれません
また、すでに使われているものを拡張できます\index{keywords!used}。

\printindex
\end{document}
```

[Overleaf でこの例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Index+example+3\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5BT1%5D%7Bfontenc%7D%0A%5Cusepackage%7Bimakeidx%7D%0A%5Cmakeindex%5Bcolumns%3D3%2C+title%3DAlphabetical+Index%5D%0A%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BIntroduction%7D%0AIn+this+example%2C+several+keywords%5Cindex%7Bkeywords%7D+will+be+used+which+%0Aare+important+and+deserve+to+appear+in+the+Index%5Cindex%7BIndex%7D.%0A%0ATerms+like+generate%5Cindex%7Bgenerate%7D+and+some%5Cindex%7Bothers%7D+will+also+%0Ashow+up.+Terms+in+the+index+can+also+be+nested+%5Cindex%7BIndex%21nested%7D%0A%0A%5Cclearpage%0A%0A%5Csection%7BSecond+section%7D%0AThis+second+section%5Cindex%7Bsection%7D+may+include+some+special+word%2C+%0Aand+expand+the+ones+already+used%5Cindex%7Bkeywords%21used%7D.%0A%0A%5Cprintindex%0A%5Cend%7Bdocument%7D)

次の画像は、上の例によって生成された出力を示しています：

![Index3OLV2.png](/files/4b36be9cd0bbfba4994f4fef4fba5191c28e9c9d)

この例では、索引はパラメータ `columns=3`を使った3列形式で表示され、タイトルは `title=Alphabetical Index`によって「Alphabetical Index」に変更されています。これらのパラメータは `\makeindex` のプリアンブルに渡されます。See the [リファレンスガイド](#reference-guide) 利用可能なパラメータとその説明の一覧は

### スタイルファイルの使用

索引をさらにカスタマイズするには、スタイルファイルを使えます。スタイルファイルは `makeindex` 最終出力の意図された形式について `<key, value>` の組を伝えます。たとえば、索引の用語を頭文字ごとにまとめ、ページ番号を右揃えにしたい場合、次のスタイルファイルで実現できます:

```latex
headings_flag 1

heading_prefix "\n\\centering\\large\\sffamily\\bfseries%
\\noindent\\textbf{"heading_suffix "}\\par\\nopagebreak\n"

item_0 "\n \\item \\small "

delim_0 " \\hfill "
delim_1 " \\hfill "
delim_2 " \\hfill "
```

これらのキーは、索引出力のさまざまな要素を変更します:

* `headings_flag 1` 新しいグループの前にグループ見出し（記号、数字、または文字）を挿入することで、グループ化を有効にします。
* `heading_prefix` 新しい文字の開始前に挿入する見出しを整形します。フォントファミリー、フォントサイズ、配置には通常の書式設定コマンドを使いますが、バックスラッシュは1つではなく2つのバックスラッシュでエスケープする必要があります。
* `item_0` は、2つの主要項目の間に挿入されるものです。
* `delim_*` キーと最初のページ番号の間に挿入される区切り記号です。

.ist ファイルで使用できるキーと値の完全な一覧については [参考ガイドに含まれる表を参照してください。](#keys-to-create-styles-files).

前のファイルが "example\_style.ist" として保存されているとします。文書でこれを使うには、次のパラメータを追加します `options= -s example_style.ist` を `\makeindex` コマンド。

```latex
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{imakeidx}
\makeindex[columns=3, title=アルファベット順索引,
           options= -s example_style.ist]

\begin{document}

\tableofcontents

\section{導入}
この例では、いくつかのキーワード\index{keywords}を使います。これらは重要で、索引\index{Index} に載る価値があります。

generate\index{generate}、great\index{great} の一覧や som other\index{others} のような重要な\index{important}用語
現れます。索引の項目は入れ子にもできます \index{Index!nested}

\clearpage

\section{第2節}
この第2の節\index{section} には何らかの特別な語が含まれているかもしれません。すでに使われているものを拡張できます\index{keywords!used}。

\printindex
\end{document}
```

[Overleaf で索引スタイルファイルを使った例を開く](https://www.overleaf.com/project/new/template/20614?id=70756423\&templateName=Using+an+index+style+file\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

次の画像は、上の例によって生成された出力を示しています：

![Index4OLV2.png](/files/04fd7d196867bd2f3e5e4a4e91a9191f93a7aa99)

## 目次に索引を含める

既定では、索引は目次に含まれませんが、これは簡単に調整できます。

```latex
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{imakeidx}
\makeindex[columns=3, title=アルファベット順索引, intoc]

\begin{document}
\tableofcontents

\section{導入}
この例では、いくつかのキーワード\index{keywords}が
使われます。これらは重要で、
索引\index{Index} に載る価値があります。

generate\index{generate} や some\index{others}
も現れます。索引の項目はまた
入れ子にできます \index{Index!nested}

\clearpage

\section{第2節}
この第2の節\index{section} には何らかの特別な
語が含まれているかもしれません。すでに使われているものを拡張できます\index{keywords!used}。

\printindex
\end{document}
```

[Overleaf でこの例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Index+example+3\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5BT1%5D%7Bfontenc%7D%0A%5Cusepackage%7Bimakeidx%7D%0A%5Cmakeindex%5Bcolumns%3D3%2C+title%3DAlphabetical+Index%2C+intoc%5D%0A%0A%5Cbegin%7Bdocument%7D%0A%5Ctableofcontents%0A%0A%5Csection%7BIntroduction%7D%0AIn+this+example%2C+several+keywords%5Cindex%7Bkeywords%7D+will+be+%0Aused+which+are+important+and+deserve+to+appear+in+the+%0AIndex%5Cindex%7BIndex%7D.%0A%0ATerms+like+generate%5Cindex%7Bgenerate%7D+and+some%5Cindex%7Bothers%7D+%0Awill+also+show+up.+Terms+in+the+index+can+also+be+%0Anested+%5Cindex%7BIndex%21nested%7D%0A%0A%5Cclearpage%0A%0A%5Csection%7BSecond+section%7D%0AThis+second+section%5Cindex%7Bsection%7D+may+include+some+special+%0Aword%2C+and+expand+the+ones+already+used%5Cindex%7Bkeywords%21used%7D.%0A%0A%5Cprintindex%0A%5Cend%7Bdocument%7D)

次の画像は、上の例によって生成された出力を示しています：

![Index5OLV2.png](/files/afc4acad9356717f27a35f89e3635359d11b3a4a)

パラメータ `intoc` をコマンド `\makeindex` に追加することで、索引タイトルを目次に含めることが有効になります。

## リファレンスガイド

### \makeindex コマンドのパラメータ

**タイトル**

特定の索引の冒頭に組版されるタイトル。例は索引の書式設定の節に示されています。

**intoc**

このオプションが渡されると、索引タイトルが目次に入ります。

**columns**

構文は key=value です。値は列数を表す整数でなければなりません。既定値は 2 です。

**columnsep**

列間の区切り幅を表す単位を指定します。構文は key=value でなければならず、たとえば columnsep=2em です。

**columnseprule**

このオプションが渡されると、列の間に縦線が描画されます。

### スタイルファイルを作成するためのキー

.ist スタイルファイルを作成するためのキー、既定値、および説明を示す次の表です。

| キー                          | 説明                                                                                                                                            |
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `actual <char>`             | '@' 次の項目が出力ファイルに現れることを示す記号。                                                                                                                   |
| `arg_close <char>`          | '}' 索引エントリ引数の閉じ区切り文字。                                                                                                                         |
| `arg_open <char>`           | '{' 索引エントリ引数の開き区切り文字。                                                                                                                         |
| `encap <char>`              | ' 残りの引数リストをページ番号の包み込みコマンドとして使うことを示す記号。                                                                                                        |
| `escape <char>`             | '\\\\' 先行する記号自体がエスケープ記号でない限り、後続の文字をエスケープする記号。注: quote は、それに続く直後の文字をエスケープするために使われますが、その前にエスケープ記号がある場合は通常の文字として扱われます。これら 2 つの記号は異なっていなければなりません。 |
| `keyword <string>`          | "\\\indexentry" makeindex に、その引数が索引エントリであることを知らせるコマンド。                                                                                        |
| `level <char>`              | '!' サブ項目の新しいレベルを示す区切り記号。                                                                                                                      |
| `quote <char>`              | '"' 注: quote は、それに続く直後の文字をエスケープするために使われますが、その前にエスケープ記号がある場合は通常の文字として扱われます。これら 2 つの記号は異なっていなければなりません。                                          |
| `range_close <char>`        | ')' 明示的なページ範囲の終わりを示す閉じ区切り文字。                                                                                                                  |
| `range_open <char>`         | '(' 明示的なページ範囲の始まりを示す開き区切り文字。                                                                                                                  |
| `preamble <string>`         | "\\\begin{theindex}\n" 出力ファイルのプリアンブル。                                                                                                         |
| `postamble <string>`        | "\n\n\\\end{theindex}\n" 出力ファイルのポストアンブル。                                                                                                      |
| `setpage_prefix <string>`   | "\n \\\setcounter{page}{" 開始ページ番号を設定するコマンドのプレフィックス。                                                                                           |
| `setpage_suffix <string>`   | "}\n" 開始ページ番号を設定するコマンドのサフィックス。                                                                                                                |
| `group_skip <string>`       | "\n\n \\\indexspace\n" 新しいグループが始まる前に挿入する縦方向の余白。                                                                                               |
| `headings_flag <string>`    | 0 新しいグループの前に挿入されるグループ見出し（記号、数字、26文字）の扱いを示すフラグ。正の値ではプレフィックスとサフィックスの間に大文字が挿入され、負の値では小文字が挿入されます（既定値は 0 で、見出しは生成されません）。                           |
| `heading_prefix <string>`   | "" 新しい文字の開始前に挿入する見出しの接頭辞。                                                                                                                     |
| `symhead_positive <string>` | "記号" headings\_flag が正のときに挿入される記号の見出し。                                                                                                        |
| `symhead_negative <string>` | "記号" headings\_flag が負のときに挿入される記号の見出し。                                                                                                        |
| `numhead_positive <string>` | "数字" headings\_flag が正のときに挿入される数字の見出し。                                                                                                        |
| `numhead_negative <string>` | "数字" headings\_flag が負のときに挿入される数字の見出し。                                                                                                        |
| `item_0 <string>`           | "\n \\\item " 2つの主要項目の間に挿入するコマンド。                                                                                                             |
| `item_1 <string>`           | "\n \\\subitem " 2つの二次項目の間に挿入するコマンド。                                                                                                          |
| `item_2 <string>`           | "\n \\\subsubitem " 2つの第3レベル項目の間に挿入するコマンド。                                                                                                    |
| `item_01 <string>`          | "\n \\\subitem " レベル 0 の項目とレベル 1 の項目の間に挿入するコマンド。                                                                                              |
| `item_x1 <string>`          | "\n \\\subitem " レベル 0 の項目とレベル 1 の項目の間に挿入するコマンドで、レベル 0 の項目に対応するページ番号がない場合に使います。                                                               |
| `item_12 <string>`          | "\n \\\subsubitem " レベル 1 の項目とレベル 2 の項目の間に挿入するコマンド。                                                                                           |
| `item_x2 <string>`          | "\n \\\subsubitem " レベル 1 の項目とレベル 2 の項目の間に挿入するコマンドで、レベル 1 の項目に対応するページ番号がない場合に使います。                                                            |
| `delim_0 <string>`          | ", " レベル 0 のキーと最初のページ番号の間に挿入する区切り記号（既定値: カンマの後に空白）。                                                                                           |
| `delim_1 <string>`          | ", " レベル 1 のキーと最初のページ番号の間に挿入する区切り記号（既定値: カンマの後に空白）。                                                                                           |
| `delim_2 <string>`          | ", " レベル 2 のキーと最初のページ番号の間に挿入する区切り記号（既定値: カンマの後に空白）。                                                                                           |
| `delim_n <string>`          | ", " どのレベルでも、同じキーに対する 2 つのページ番号の間に挿入する区切り記号（既定値: カンマの後に空白）。                                                                                   |
| `delim_r <string>`          | "--" 範囲の開始ページ番号と終了ページ番号の間に挿入する区切り記号。                                                                                                          |
| `delim_t <string>`          | "" ページ一覧の末尾に挿入する区切り記号。この区切り記号は、対応するページ一覧を持たない項目には影響しません。                                                                                      |
| `encap_prefix <string>`     | "\\\\" ページ番号を包み込むコマンドの接頭辞の先頭部分。                                                                                                               |
| `encap_infix <string>`      | "{" ページ番号を包み込むコマンドの接頭辞の2番目の部分。                                                                                                                |
| `encap_suffix <string>`     | "}" ページ番号を包み込むコマンドの接尾辞。                                                                                                                       |
| `line_max <number>`         | 72 出力における1行の最大長。これを超えると行が折り返されます。                                                                                                             |
| `indent_space <string>`     | "\t\t" 折り返された行の先頭に挿入する空白（既定値: タブ2つ）。                                                                                                          |
| `indent_length <number>`    | 16 indent\_space の長さ（既定値: 16、タブ2つに相当）。                                                                                                        |

## さらに読む

詳しくは以下を参照してください：

* [用語集](/latex/ja/wen-shu-gou-zao/05-glossaries.md)
* [表と図の一覧](/latex/ja/to/03-lists-of-tables-and-figures.md)
* [目次](/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/09-hyperlinks.md)
* [国際言語サポート](/latex/ja/yan-yu/03-international-language-support.md)
* [節や数式の相互参照](/latex/ja/wen-shu-gou-zao/03-cross-referencing-sections-equations-and-floats.md)
* [大規模プロジェクトでの管理](/latex/ja/wen-shu-gou-zao/07-management-in-a-large-project.md)
* [複数ファイルの LaTeX プロジェクト](/latex/ja/wen-shu-gou-zao/08-multi-file-latex-projects.md)
* [imakeidx パッケージのドキュメント](http://mirror.math.ku.edu/tex-archive/macros/latex/contrib/imakeidx/imakeidx.pdf)


---

# 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/04-indices.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.
