> 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/ja/wen-shu-gou-zao/04-indices.md).

# 索引

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

## はじめに

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

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

\begin{document}
\section{Introduction}
この例では、いくつかのキーワード\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{Introduction}
この例では、いくつかのキーワード\index{keywords}を使用します
それらは重要で、索引\index{Index}に載る価値があります。

generate\index{generate} や some\index{others} のような用語も
表示されます。索引内の用語はネストすることもできます \index{Index!nested}

\clearpage

\section{Second section}
この第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)

索引の用語を特殊な形容詞まで含めて拡張するのは一般的です。たとえば、 *Field* という語は、形容詞 *finite* が前に付くか *characteristic 0*が後ろに付くと、特別な意味を持つことがあります。また、索引に異なる種類の *Field*を別々の項目として追加するのは少し面倒です。このような場合は、感嘆符「!」を追加すると、この記号の後ろの語を親項目のサブ項目として追加できます *Field*.

この例では、「Index」という語の「nested」がサブ項目になっています。

## 索引の書式設定

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

```latex
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{imakeidx}
\makeindex[columns=3, title=Alphabetical Index]

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

generate\index{generate} や some\index{others} のような用語も
表示されます。索引内の用語はネストすることもできます \index{Index!nested}

\clearpage

\section{Second section}
この第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` プリアンブル内の [リファレンスガイド](#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_*` キーと最初のページ番号の間に挿入される区切り文字です。

&#x20;.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=Alphabetical Index,
           options= -s example_style.ist]

\begin{document}

\tableofcontents

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

generate\index{generate}、great\index{great} の一覧、そして重要かもしれない\index{important}ほかの\index{others}用語のようなものも
表示されます。索引内の用語はネストすることもできます \index{Index!nested}

\clearpage

\section{Second section}
この第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=Alphabetical Index, intoc]

\begin{document}
\tableofcontents

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

generate\index{generate} や some\index{others}
も表示されます。索引内の用語は
ネストすることもできます \index{Index!nested}

\clearpage

\section{Second section}
この第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 コマンドのパラメータ

**title**

特定の索引の冒頭に組版するタイトル。例は「索引の書式設定」にあります。

**intoc**

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

**columns**

key=value 構文を使います。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>` | "Symbols" headings\_flag が正のときに挿入される記号の見出し。                                                                                                      |
| `symhead_negative <string>` | "symbols" headings\_flag が負のときに挿入される記号の見出し。                                                                                                      |
| `numhead_positive <string>` | "Numbers" headings\_flag が正のときに挿入される数字の見出し。                                                                                                      |
| `numhead_negative <string>` | "numbers" headings\_flag が負のときに挿入される数字の見出し。                                                                                                      |
| `item_0 <string>`           | "\n \\\item " 2つの主要項目（レベル0）の間に挿入されるコマンド。                                                                                                         |
| `item_1 <string>`           | "\n \\\subitem " 2つの副項目（レベル1）の間に挿入されるコマンド。                                                                                                       |
| `item_2 <string>`           | "\n \\\subsubitem " 2つのレベル2項目の間に挿入されるコマンド。                                                                                                       |
| `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://ayakaleaf-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.
