> 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/to/01-tables.md).

# 表

Overleaf では表を挿入する方法は 3 つあります:

1. を使うと [**表を挿入** ボタンをクリックします](/latex/ja/narejjibsu/067-how-to-generate-and-insert-latex-tables-in-overleaf.md#inserttable) エディタのツールバーで。
2. を使いながら、別の文書から表をコピーして貼り付ける **ビジュアルエディター**.
3. 表の LaTeX コードを **コードエディター**.

LaTeX が初めてなら、 [のツールバーを使うのは **ビジュアルエディター**](/latex/ja/narejjibsu/067-how-to-generate-and-insert-latex-tables-in-overleaf.md#inserttable) （オプション 1）は始めるのに最適です。そして、 **ビジュアルエディター** や **コードエディター** 表の背後にあるコードを見ることができます。 **このページではオプション 3 に焦点を当てます。**

## LaTeX で簡単な表を作成する

まずは、表の最も簡単な例の 1 つから始めましょう:

```latex
\begin{center}
\begin{tabular}{ c c c }
 cell1 & cell2 & cell3 \\
 cell4 & cell5 & cell6 \\
 cell7 & cell8 & cell9
\end{tabular}
\end{center}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+a+basic+table\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bcenter%7D%0A%5Cbegin%7Btabular%7D%7B+c+c+c+%7D%0A+cell1+%26+cell2+%26+cell3+%5C%5C+%0A+cell4+%26+cell5+%26+cell6+%5C%5C++%0A+cell7+%26+cell8+%26+cell9++++%0A%5Cend%7Btabular%7D%0A%5Cend%7Bcenter%7D%0A%5Cend%7Bdocument%7D)

![表の例](/files/6fb4e065a5e7b4e89478f172d0e620ac8ffba6bd)

この `tabular` 環境は、表を作成するための標準的な LaTeX の方法です。この環境にはパラメータを指定する必要があります。ここでは `{c c c}` これは、LaTeX に 3 列あることを伝え、それぞれの列内のテキストを中央揃えにする指定です。

この `tabular` 環境は追加の柔軟性を提供します。たとえば、各列の間に区切り線を入れることができます:

```latex
\begin{center}
\begin{tabular}{ |c|c|c| }
 \\hline
 cell1 & cell2 & cell3 \\
 cell4 & cell5 & cell6 \\
 cell7 & cell8 & cell9 \\
 \\hline
\end{tabular}
\end{center}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+a+basic+table+with+separator+lines\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bcenter%7D%0A%5Cbegin%7Btabular%7D%7B+%7Cc%7Cc%7Cc%7C+%7D+%0A+%5Chline%0A+cell1+%26+cell2+%26+cell3+%5C%5C+%0A+cell4+%26+cell5+%26+cell6+%5C%5C+%0A+cell7+%26+cell8+%26+cell9+%5C%5C+%0A+%5Chline%0A%5Cend%7Btabular%7D%0A%5Cend%7Bcenter%7D%0A%5Cend%7Bdocument%7D)

![簡単な表の例](/files/b52f4feb44406ec7aec47dc3f9411ce299251f43)

以下に、上の例で使われている構成要素の説明を示します:

**{ |c|c|c| }**

これは、縦線で区切られた 3 列を表で使うことを宣言しています。各 c は、その列の内容が中央揃えになることを意味します。r を使うと右揃え、l を使うと左揃えにもできます。

**\\\hline**

これにより、表の上部と下部に横線が入ります。\hline を使える回数に制限はありません。

**cell1 & cell2 & cell3 \\\\**

& はセル区切りで、ダブルバックスラッシュ \\\ がこの行の終わりを示します。

以下では、さまざまな縦線と横線（しばしば「ルール」と呼ばれます）を使った 2 番目の例を示します:

```latex
\begin{center}
\\begin{tabular}{||c c c c||}
 \\hline
 Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
 \\hline\\hline
 1 & 6 & 87837 & 787 \\
 \\hline
 2 & 7 & 78 & 5415 \\
 \\hline
 3 & 545 & 778 & 7507 \\
 \\hline
 4 & 545 & 18744 & 7560 \\
 \\hline
 5 & 88 & 788 & 6344 \\ [1ex]
 \\hline
\end{tabular}
\end{center}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Basic+table+with+horizontal+and+vertical+rules\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bcenter%7D%0A%5Cbegin%7Btabular%7D%7B%7C%7Cc+c+c+c%7C%7C%7D+%0A+%5Chline%0A+Col1+%26+Col2+%26+Col2+%26+Col3+%5C%5C+%5B0.5ex%5D+%0A+%5Chline%5Chline%0A+1+%26+6+%26+87837+%26+787+%5C%5C+%0A+%5Chline%0A+2+%26+7+%26+78+%26+5415+%5C%5C%0A+%5Chline%0A+3+%26+545+%26+778+%26+7507+%5C%5C%0A+%5Chline%0A+4+%26+545+%26+18744+%26+7560+%5C%5C%0A+%5Chline%0A+5+%26+88+%26+788+%26+6344+%5C%5C+%5B1ex%5D+%0A+%5Chline%0A%5Cend%7Btabular%7D%0A%5Cend%7Bcenter%7D%0A%5Cend%7Bdocument%7D)

![hline を使った表の例](/files/f825eff9b282138a326a37dd50b1525ceb7d0fca)

## 固定幅の表

表を整形するとき、各列または表全体に固定幅が必要になることがあります。次の例では `array` パッケージを文書のプリアンブルに追加し:

```latex
\usepackage{array}
```

そして、それを使って列幅を固定します:

```latex
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{center}
\begin{tabular}{ | m{5em} | m{1cm}| m{1cm} | }
  \\hline
  cell1 dummy text dummy text dummy text& cell2 & cell3 \\
  \\hline
  cell1 dummy text dummy text dummy text & cell5 & cell6 \\
  \\hline
  cell7 & cell8 & cell9 \\
  \\hline
\end{tabular}
\end{center}
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Table+with+fixed+column+width\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Barray%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bcenter%7D%0A%5Cbegin%7Btabular%7D%7B+%7C+m%7B5em%7D+%7C+m%7B1cm%7D%7C+m%7B1cm%7D+%7C+%7D+%0A++%5Chline%0A++cell1+dummy+text+dummy+text+dummy+text%26+cell2+%26+cell3+%5C%5C+%0A++%5Chline%0A++cell1+dummy+text+dummy+text+dummy+text+%26+cell5+%26+cell6+%5C%5C+%0A++%5Chline%0A++cell7+%26+cell8+%26+cell9+%5C%5C+%0A++%5Chline%0A%5Cend%7Btabular%7D%0A%5Cend%7Bcenter%7D%0A%5Cend%7Bdocument%7D)

![固定幅の表の例](/files/32b0be36d9ab03b3c4886ec29f00c1598c7de58e)

その `tabular` 環境では、パラメータ `m{5em}` は幅を `5em` で第 1 列の幅を（`1cm` で残りの 2 列の幅を設定し、テキストをセルの中央に配置します。配置オプションは `m` 中央揃えの `p` 上揃えの `b` 下揃えのです。これらのパラメータを使うと、テキストは各セル内に収まるよう自動的に整形されます。

各セルの幅を制御する必要がなく、表全体の幅を指定してその中でスペースを均等に配分したい場合は、 `tabularx` パッケージを使います。以下の例を参照してください:

```latex
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{0.8\textwidth} {
  | >{\raggedright\arraybackslash}X
  | >{\centering\arraybackslash}X
  | >{\raggedleft\arraybackslash}X | }
 \\hline
 item 11 & item 12 & item 13 \\
 \\hline
 item 21  & item 22  & item 23  \\
\\hline
\end{tabularx}
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Table+example+using+tabularx+package\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Btabularx%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Btabularx%7D%7B0.8%5Ctextwidth%7D+%7B+%0A++%7C+%3E%7B%5Craggedright%5Carraybackslash%7DX+%0A++%7C+%3E%7B%5Ccentering%5Carraybackslash%7DX+%0A++%7C+%3E%7B%5Craggedleft%5Carraybackslash%7DX+%7C+%7D%0A+%5Chline%0A+item+11+%26+item+12+%26+item+13+%5C%5C%0A+%5Chline%0A+item+21++%26+item+22++%26+item+23++%5C%5C%0A%5Chline%0A%5Cend%7Btabularx%7D%0A%5Cend%7Bdocument%7D)

![tabularx パッケージを使った表の例](/files/0425b66bad240cce8dcf32193a6533a45d97e5a5)

環境 `tabularx` に似ていますが `tabular` より柔軟です。使うには、 `\usepackage{tabularx}` を文書のプリアンブルに追加します。環境の開始文が異なることに注意してください。この例では、表の幅は `0.8\textwidth`に設定されており、これは文書の本文幅の 80% です。次のいずれかの [LaTeX の単位](/latex/ja/shu-shi-she-ding/01-lengths-in-latex.md) を使ってその値を設定できます。

波括弧内の接頭辞 `| >{\raggedright\arraybackslash}X | >{\centering\arraybackslash}X | >{\raggedleft\arraybackslash}X |` は各列の配置を設定します。1 列目を *左*、2 列目を *center* 、3 列目を *右*.

## 行と列を結合する

行と列を結合して、より大きな表セルを作成できます。次の例では `\multicolumn` コマンドを使って複数の列を結合しています:

```latex
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{ |p{3cm}||p{3cm}|p{3cm}|p{3cm}|  }
 \\hline
 \multicolumn{4}{|c|}{Country List} \\
 \\hline
 Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 Code&ISO numeric Code\\
 \\hline
 Afghanistan   & AF    &AFG&   004\\
 Aland Islands&   AX  & ALA   &248\\
 Albania &AL & ALB&  008\\
 Algeria    &DZ & DZA&  012\\
 American Samoa&   AS  & ASM&016\\
 Andorra& AD  & AND   &020\\
 Angola& AO  & AGO&024\\
 \\hline
\end{tabular}
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+table+using+the+multicolumn+command\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bmultirow%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Btabular%7D%7B+%7Cp%7B3cm%7D%7C%7Cp%7B3cm%7D%7Cp%7B3cm%7D%7Cp%7B3cm%7D%7C++%7D%0A+%5Chline%0A+%5Cmulticolumn%7B4%7D%7B%7Cc%7C%7D%7BCountry+List%7D+%5C%5C%0A+%5Chline%0A+Country+Name+or+Area+Name%26+ISO+ALPHA+2+Code+%26ISO+ALPHA+3+Code%26ISO+numeric+Code%5C%5C%0A+%5Chline%0A+Afghanistan+++%26+AF++++%26AFG%26+++004%5C%5C%0A+Aland+Islands%26+++AX++%26+ALA+++%26248%5C%5C%0A+Albania+%26AL+%26+ALB%26++008%5C%5C%0A+Algeria++++%26DZ+%26+DZA%26++012%5C%5C%0A+American+Samoa%26+++AS++%26+ASM%26016%5C%5C%0A+Andorra%26+AD++%26+AND+++%26020%5C%5C%0A+Angola%26+AO++%26+AGO%26024%5C%5C%0A+%5Chline%0A%5Cend%7Btabular%7D%0A%5Cend%7Bdocument%7D)

![\multicolumn コマンドを使った表の例](/files/65a071c9ba673b9f70e58f1aa6824bf4b6bc32cd)

コマンドの各要素を見てみましょう `\multicolumn{4}{|c|}{Country List} \\`:

**{4}**

結合する列の数。ここでは 4 です。

**{|c|}**

結果のセルの区切りと配置。ここではテキストは中央揃えになり、セルの両側に縦線が引かれます。

**{Country List}**

セル内に表示するテキスト。

行を結合するには、 `multirow` パッケージを文書のプリアンブルに追加する必要があります:

```latex
\usepackage{multirow}
```

その後、 `\multirow` コマンドを文書内で使えます:

```latex
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{center}
\begin{tabular}{ |c|c|c| }
\\hline
col1 & col2 & col3 \\
\\hline
\multirow{3}{4em}{Multiple row} & cell2 & cell3 \\
& cell5 & cell6 \\
& cell8 & cell9 \\
\\hline
\end{tabular}
\end{center}
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Multirow+table+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bmultirow%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bcenter%7D%0A%5Cbegin%7Btabular%7D%7B+%7Cc%7Cc%7Cc%7C+%7D+%0A%5Chline%0Acol1+%26+col2+%26+col3+%5C%5C%0A%5Chline%0A%5Cmultirow%7B3%7D%7B4em%7D%7BMultiple+row%7D+%26+cell2+%26+cell3+%5C%5C+%0A%26+cell5+%26+cell6+%5C%5C+%0A%26+cell8+%26+cell9+%5C%5C+%0A%5Chline%0A%5Cend%7Btabular%7D%0A%5Cend%7Bcenter%7D%0A%5Cend%7Bdocument%7D)

![multirow コマンドを使った表の例](/files/980bbac95dd5844507b0beaeff1a343084c26dd0)

この `multirow` コマンドは 3 つのパラメータを取ります。例では次の設定を使っています:

1. 結合する行数: `3`
2. 列の幅: `4em`
3. セルの内容: `複数行`

## 複数ページにわたる表

文書内で 2 ページ以上にわたる非常に長い表を挿入する必要がある場合は、 `longtable` パッケージです。まず、次の行を文書のプリアンブルに追加します:

```latex
\usepackage{longtable}
```

その後、 `longtable` 次の例に示すように、～環境を使います:

```latex
\documentclass{article}
\usepackage{longtable}

\begin{document}

 \begin{longtable}[c]{| c | c |}
 \caption{Long table caption.\label{long}}\\

 \\hline
 \multicolumn{2}{| c |}{表の開始}\\
 \\hline
 何か & ほかの何か\\
 \\hline
 \endfirsthead

 \\hline
 \multicolumn{2}{|c|}{表 \ref{long} の続き}\\
 \\hline
 何か & ほかの何か\\
 \\hline
 \endhead

 \\hline
 \endfoot

 \\hline
 \multicolumn{2}{| c |}{表の終了}\\
 \\hline\\hline
 \endlastfoot

 たくさんの行 & こんな感じ\\
 たくさんの行 & こんな感じ\\
 たくさんの行 & こんな感じ\\
 たくさんの行 & こんな感じ\\
 たくさんの行 & こんな感じ\\
 たくさんの行 & こんな感じ\\
 たくさんの行 & こんな感じ\\
 たくさんの行 & こんな感じ\\
 ...
 たくさんの行 & こんな感じ\\
 \end{longtable}
```

![行数の多い表の例](/files/5d0821e239d5e239199b0ebf1b138ac40236641d)

[1つ開く `longtable` Overleaf 上の例を開く](https://www.overleaf.com/project/new/template/20823?id=71401569\&templateName=Longtable+example\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

～の動作は `longtable` デフォルトの～と似ていますが `tabular`、標準の LaTeX のページ分割アルゴリズムで分割可能な表を生成します。～専用の `longtable`要素が 4 つあります:

**\endfirsthead**

このコマンドより上の内容はすべて、最初のページの表の先頭に表示されます。

**\endhead**

このコマンドの前、かつ \endfirsthead の下に置いたものは、最初のページ以外のすべてのページで表の上部に表示されます。

**\endfoot**

\endhead と同様に、\endhead の後でこのコマンドの前に置いたものは、最後のページ以外のすべてのページで表の下部に表示されます。

**\endlastfoot**

\endfirsthead と同様です。\endfoot の後でこのコマンドの前にある要素は、表が表示される最後のページにのみ、表の下部に表示されます。

## 表の配置

表が float 内にあれば、配置は簡単です `table` 環境内で。

```latex
\documentclass{article}
\begin{document}
以下はちょうどここに配置された表です:
\\begin{table}[h!]
\centering
 \\begin{tabular}{||c c c c||}
 \\hline
 Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
 \\hline\\hline
 1 & 6 & 87837 & 787 \\
 2 & 7 & 78 & 5415 \\
 3 & 545 & 778 & 7507 \\
 4 & 545 & 18744 & 7560 \\
 5 & 88 & 788 & 6344 \\ [1ex]
 \\hline
 \end{tabular}
\\end{table}
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Positioning+a+table\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0ABelow+is+a+table+positioned+exactly+here%3A%0A%5Cbegin%7Btable%7D%5Bh%21%5D%0A%5Ccentering%0A+%5Cbegin%7Btabular%7D%7B%7C%7Cc+c+c+c%7C%7C%7D+%0A+%5Chline%0A+Col1+%26+Col2+%26+Col2+%26+Col3+%5C%5C+%5B0.5ex%5D+%0A+%5Chline%5Chline%0A+1+%26+6+%26+87837+%26+787+%5C%5C+%0A+2+%26+7+%26+78+%26+5415+%5C%5C%0A+3+%26+545+%26+778+%26+7507+%5C%5C%0A+4+%26+545+%26+18744+%26+7560+%5C%5C%0A+5+%26+88+%26+788+%26+6344+%5C%5C+%5B1ex%5D+%0A+%5Chline%0A+%5Cend%7Btabular%7D%0A%5Cend%7Btable%7D%0A%5Cend%7Bdocument%7D)

![表の配置の例](/files/39a8d4247226177a59922d614d3ea463c7fac4b4)

パラメータ `h!` 表の環境宣言に渡されると、この表を配置する場所が定められます *こちら*、そして LaTeX の既定値を上書きします。指定できる配置パラメータには次のものがあります:

**h**

表をここに大まかに配置します。

**t**

表をページ上部に配置します。

**b**

表をページ下部に配置します。

**p**

表専用の特別なページに配置します。

**!**

内部の LaTeX パラメータを上書きします。

**H**

h! とほぼ同様に、表をこの正確な位置に配置します。

表の配置に関するさらなる例は、 [画像と表の配置](/latex/ja/to/02-positioning-images-and-tables.md) 記事を参照してください。

この例では、ほかにもいくつかのコマンドがあります:

**\centering**

float コンテナ要素に対して表を中央揃えにします。

**\[1ex]**

これによりセルに追加のスペースが加わります。

## キャプション、ラベル、参照

表には caption、label、参照を付けることができます。そのために使うのが `table` 環境内で。

```latex
\documentclass{article}
\begin{document}
Table \ref{table:1} は、参照付き \LaTeX{} 要素の例です。

\\begin{table}[h!]
\centering
\\begin{tabular}{||c c c c||}
 \\hline
 Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
 \\hline\\hline
 1 & 6 & 87837 & 787 \\
 2 & 7 & 78 & 5415 \\
 3 & 545 & 778 & 7507 \\
 4 & 545 & 18744 & 7560 \\
 5 & 88 & 788 & 6344 \\ [1ex]
 \\hline
\end{tabular}
\\caption{キャプションとラベルをテストするための表。}
\label{table:1}
\\end{table}
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Table+captions+and+labels\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0ATable+%5Cref%7Btable%3A1%7D+is+an+example+of+a+referenced+%5CLaTeX%7B%7D+element.%0A%0A%5Cbegin%7Btable%7D%5Bh%21%5D%0A%5Ccentering%0A%5Cbegin%7Btabular%7D%7B%7C%7Cc+c+c+c%7C%7C%7D+%0A+%5Chline%0A+Col1+%26+Col2+%26+Col2+%26+Col3+%5C%5C+%5B0.5ex%5D+%0A+%5Chline%5Chline%0A+1+%26+6+%26+87837+%26+787+%5C%5C+%0A+2+%26+7+%26+78+%26+5415+%5C%5C%0A+3+%26+545+%26+778+%26+7507+%5C%5C%0A+4+%26+545+%26+18744+%26+7560+%5C%5C%0A+5+%26+88+%26+788+%26+6344+%5C%5C+%5B1ex%5D+%0A+%5Chline%0A%5Cend%7Btabular%7D%0A%5Ccaption%7BTable+to+test+captions+and+labels.%7D%0A%5Clabel%7Btable%3A1%7D%0A%5Cend%7Btable%7D%0A%5Cend%7Bdocument%7D)

![参照付き LaTeX 要素の例](/files/0aec68cee4411958f54e2c89d16aed164b9591ff)

この例には重要なコマンドが 3 つあります:

**\caption{Table to test captions and labels}**

予想どおり、このコマンドは表のキャプションを設定します。表の一覧を作成すると、このキャプションがそこで使われます。キャプションは表の上にも下にも置けます。

**\label{table:1}**

文書内で表を参照する必要がある場合は、このコマンドでラベルを設定します。ラベルによって表に番号が付き、\ref コマンドと組み合わせることで参照できるようになります。

**\ref{table:1}**

このコードは、参照先の表に対応する番号に置き換えられます。

## 表の一覧

表の一覧を作成するには、 `\listoftables` コマンドを使います。各表のキャプションがこの一覧の生成に使われます。～でサポートされている言語では、 `babel` パッケージにより、タイトル「List of tables」は各言語に応じて翻訳されます。～に関する記事を参照してください [国際言語サポート](/latex/ja/yan-yu/03-international-language-support.md) 詳しくは

```latex
\documentclass{article}
\begin{document}
\listoftables
\vspace{5pt}
表 \ref{table:1} は、参照付き \LaTeX{} 要素の例です。

\\begin{table}[h!]
\centering
\\begin{tabular}{||c c c c||}
 \\hline
 Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
 \\hline\\hline
 1 & 6 & 87837 & 787 \\
 2 & 7 & 78 & 5415 \\
 3 & 545 & 778 & 7507 \\
 4 & 545 & 18744 & 7560 \\
 5 & 88 & 788 & 6344 \\ [1ex]
 \\hline
\end{tabular}
\caption{This is the caption for the first table.}
\label{table:1}
\\end{table}

\\begin{table}[h!]
\centering
\\begin{tabular}{||c c c c||}
 \\hline
 Col1 & Col2 & Col2 & Col3 \\ [0.5ex]
 \\hline\\hline
  4 & 545 & 18744 & 7560 \\
 5 & 88 & 788 & 6344 \\ [1ex]
 \\hline
\end{tabular}
\caption{This is the caption for the second table.}
\label{table:2}
\\end{table}
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+using+listoftables\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Clistoftables%0A%5Cvspace%7B5pt%7D%0AThe+table+%5Cref%7Btable%3A1%7D+is+an+example+of+referenced+%5CLaTeX%7B%7D+elements.%0A%0A%5Cbegin%7Btable%7D%5Bh%21%5D%0A%5Ccentering%0A%5Cbegin%7Btabular%7D%7B%7C%7Cc+c+c+c%7C%7C%7D+%0A+%5Chline%0A+Col1+%26+Col2+%26+Col2+%26+Col3+%5C%5C+%5B0.5ex%5D+%0A+%5Chline%5Chline%0A+1+%26+6+%26+87837+%26+787+%5C%5C+%0A+2+%26+7+%26+78+%26+5415+%5C%5C%0A+3+%26+545+%26+778+%26+7507+%5C%5C%0A+4+%26+545+%26+18744+%26+7560+%5C%5C%0A+5+%26+88+%26+788+%26+6344+%5C%5C+%5B1ex%5D+%0A+%5Chline%0A%5Cend%7Btabular%7D%0A%5Ccaption%7BThis+is+the+caption+for+the+first+table.%7D%0A%5Clabel%7Btable%3A1%7D%0A%5Cend%7Btable%7D%0A%0A%5Cbegin%7Btable%7D%5Bh%21%5D%0A%5Ccentering%0A%5Cbegin%7Btabular%7D%7B%7C%7Cc+c+c+c%7C%7C%7D+%0A+%5Chline%0A+Col1+%26+Col2+%26+Col2+%26+Col3+%5C%5C+%5B0.5ex%5D+%0A+%5Chline%5Chline%0A++4+%26+545+%26+18744+%26+7560+%5C%5C%0A+5+%26+88+%26+788+%26+6344+%5C%5C+%5B1ex%5D+%0A+%5Chline%0A%5Cend%7Btabular%7D%0A%5Ccaption%7BThis+is+the+caption+for+the+second+table.%7D%0A%5Clabel%7Btable%3A2%7D%0A%5Cend%7Btable%7D%0A%5Cend%7Bdocument%7D)

![表の一覧の例](/files/e88112691dc39ddd54aa9f8f4fb8a02721c689bf)

## 表の見た目を変更する

表の要素はいくつか変更して、文書の要件に合わせることができます。以下では、線の太さ、線の色、セルの背景色を変更する方法を学びます。

### 線幅とセル内余白

列間隔と行の伸縮を大きくすると、表の可読性が向上することがあります。

```latex
\documentclass{article}
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{1.5}
\begin{document}
\begin{tabular}{ |p{3cm}|p{3cm}|p{3cm}|  }
\\hline
\multicolumn{3}{|c|}{Country List} \\
\\hline
Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 \\
\\hline
Afghanistan & AF &AFG \\
Aland Islands & AX   & ALA \\
Albania &AL & ALB \\
Algeria    &DZ & DZA \\
American Samoa & AS & ASM \\
Andorra & AD & AND   \\
Angola & AO & AGO \\
\\hline
\end{tabular}
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Changing+table+spacing\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Csetlength%7B%5Carrayrulewidth%7D%7B0.5mm%7D%0A%5Csetlength%7B%5Ctabcolsep%7D%7B18pt%7D%0A%5Crenewcommand%7B%5Carraystretch%7D%7B1.5%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Btabular%7D%7B+%7Cp%7B3cm%7D%7Cp%7B3cm%7D%7Cp%7B3cm%7D%7C++%7D%0A%5Chline%0A%5Cmulticolumn%7B3%7D%7B%7Cc%7C%7D%7BCountry+List%7D+%5C%5C%0A%5Chline%0ACountry+Name+or+Area+Name%26+ISO+ALPHA+2+Code+%26ISO+ALPHA+3+%5C%5C%0A%5Chline%0AAfghanistan+%26+AF+%26AFG+%5C%5C%0AAland+Islands+%26+AX+++%26+ALA+%5C%5C%0AAlbania+%26AL+%26+ALB+%5C%5C%0AAlgeria++++%26DZ+%26+DZA+%5C%5C%0AAmerican+Samoa+%26+AS+%26+ASM+%5C%5C%0AAndorra+%26+AD+%26+AND+++%5C%5C%0AAngola+%26+AO+%26+AGO+%5C%5C%0A%5Chline%0A%5Cend%7Btabular%7D%0A%5Cend%7Bdocument%7D)

![列間隔の例](/files/4e1cc9bea53f16e4d7b76f668e2cadcc52c7a95a)

コマンドの説明を以下に示します:

**\setlength{\arrayrulewidth}{0.5mm}**

これにより表の罫線の太さを設定します。例では 0.5mm ですが、ほかの単位も使えます。完全な一覧は記事「Lengths in LaTeX」を参照してください。

**\setlength{\tabcolsep}{18pt}**

このコマンドにより、テキストとそれを含むセルの左右の境界との間隔を 18pt に設定します。必要に応じてほかの単位も使えます。

**\renewcommand{\arraystretch}{1.5}**

各行の高さは、既定の高さの 1.5 倍に設定されます。

### 交互の行に色を付ける

表の行に交互の色を適用するには、 `xcolor` パッケージと `table` オプションを使います。次の例で示します:

```latex
\documentclass{article}
\usepackage[table]{xcolor}
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{2.5}
\begin{document}
{\rowcolors{3}{green!80!yellow!50}{green!70!yellow!40}
\begin{tabular}{ |p{3cm}|p{3cm}|p{3cm}|  }
\\hline
\multicolumn{3}{|c|}{Country List} \\
\\hline
Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 \\
\\hline
Afghanistan & AF &AFG \\
Aland Islands & AX   & ALA \\
Albania &AL & ALB \\
Algeria    &DZ & DZA \\
American Samoa & AS & ASM \\
Andorra & AD & AND   \\
Angola & AO & AGO \\
\\hline
\end{tabular}}
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Changing+row+colours\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Btable%5D%7Bxcolor%7D%0A%5Csetlength%7B%5Carrayrulewidth%7D%7B0.5mm%7D%0A%5Csetlength%7B%5Ctabcolsep%7D%7B18pt%7D%0A%5Crenewcommand%7B%5Carraystretch%7D%7B2.5%7D%0A%5Cbegin%7Bdocument%7D%0A%7B%5Crowcolors%7B3%7D%7Bgreen%2180%21yellow%2150%7D%7Bgreen%2170%21yellow%2140%7D%0A%5Cbegin%7Btabular%7D%7B+%7Cp%7B3cm%7D%7Cp%7B3cm%7D%7Cp%7B3cm%7D%7C++%7D%0A%5Chline%0A%5Cmulticolumn%7B3%7D%7B%7Cc%7C%7D%7BCountry+List%7D+%5C%5C%0A%5Chline%0ACountry+Name+or+Area+Name%26+ISO+ALPHA+2+Code+%26ISO+ALPHA+3+%5C%5C%0A%5Chline%0AAfghanistan+%26+AF+%26AFG+%5C%5C%0AAland+Islands+%26+AX+++%26+ALA+%5C%5C%0AAlbania+%26AL+%26+ALB+%5C%5C%0AAlgeria++++%26DZ+%26+DZA+%5C%5C%0AAmerican+Samoa+%26+AS+%26+ASM+%5C%5C%0AAndorra+%26+AD+%26+AND+++%5C%5C%0AAngola+%26+AO+%26+AGO+%5C%5C%0A%5Chline%0A%5Cend%7Btabular%7D%7D%0A%5Cend%7Bdocument%7D)

![表の行に色を付ける例](/files/210e770a051d35b4a0ec33171a97da08ff373d97)

コマンドの直前にある波括弧に注意してください

```latex
\rowcolors{3}{green!80!yellow!50}{green!70!yellow!40}
```

そして、その後の `tabular` 環境です。コマンド `\rowcolors` は、波括弧内で渡される 3 つのパラメータを取ります:

* 開始する行、
* 奇数行の色、
* 偶数行の色。

次を参照してください `xcolor` パッケージのドキュメント（～の [参考資料](#further-reading) セクション）を参照すると、使用可能な色の一覧や独自の色の作り方がわかります。この例では、緑と黄がさまざまな割合で混ぜられています。

コマンドを機能させるには、必ず～を追加してください

```latex
\usepackage[table]{xcolor}
```

LaTeX ファイルのプリアンブルに

### 表に色を付ける（セル、行、列、線）

表のすべての要素は、特定の色を使うようにカスタマイズできます。これもまた、～によって提供されます **xcolor** したがって、～を追加する必要があります

```latex
\usepackage[table]{xcolor}
```

をプリアンブルに。以下に例を示します。

```latex
\documentclass{article}
\usepackage[table]{xcolor}
\setlength{\arrayrulewidth}{1mm}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{2.5}
\newcolumntype{s}{>{\columncolor[HTML]{AAACED}} p{3cm}}
\arrayrulecolor[HTML]{DB5800}
\begin{document}
\begin{tabular}{ |s|p{3cm}|p{3cm}| }
\\hline
\rowcolor{lightgray} \multicolumn{3}{|c|}{Country List} \\
\\hline
Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 \\
\\hline
Afghanistan & AF &AFG \\
\rowcolor{gray}
Aland Islands & AX & ALA \\
Albania   &AL & ALB \\
Algeria  &DZ & DZA \\
American Samoa & AS & ASM \\
Andorra & AD & \cellcolor[HTML]{AA0044} AND    \\
Angola & AO & AGO \\
\\hline
\end{tabular}
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+using+colour+in+a+table\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Btable%5D%7Bxcolor%7D%0A%5Csetlength%7B%5Carrayrulewidth%7D%7B1mm%7D%0A%5Csetlength%7B%5Ctabcolsep%7D%7B18pt%7D%0A%5Crenewcommand%7B%5Carraystretch%7D%7B2.5%7D%0A%5Cnewcolumntype%7Bs%7D%7B%3E%7B%5Ccolumncolor%5BHTML%5D%7BAAACED%7D%7D+p%7B3cm%7D%7D%0A%5Carrayrulecolor%5BHTML%5D%7BDB5800%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Btabular%7D%7B+%7Cs%7Cp%7B3cm%7D%7Cp%7B3cm%7D%7C+%7D%0A%5Chline%0A%5Crowcolor%7Blightgray%7D+%5Cmulticolumn%7B3%7D%7B%7Cc%7C%7D%7BCountry+List%7D+%5C%5C%0A%5Chline%0ACountry+Name+or+Area+Name%26+ISO+ALPHA+2+Code+%26ISO+ALPHA+3+%5C%5C%0A%5Chline%0AAfghanistan+%26+AF+%26AFG+%5C%5C%0A%5Crowcolor%7Bgray%7D%0AAland+Islands+%26+AX+%26+ALA+%5C%5C%0AAlbania+++%26AL+%26+ALB+%5C%5C%0AAlgeria++%26DZ+%26+DZA+%5C%5C%0AAmerican+Samoa+%26+AS+%26+ASM+%5C%5C%0AAndorra+%26+AD+%26+%5Ccellcolor%5BHTML%5D%7BAA0044%7D+AND++++%5C%5C%0AAngola+%26+AO+%26+AGO+%5C%5C%0A%5Chline%0A%5Cend%7Btabular%7D%0A%5Cend%7Bdocument%7D)

![表で色をカスタマイズした例](/files/7ae073f27e2d486a8c42da58c5967f624c19fde4)

以下に、表の各要素の色を変更する方法を説明します:

* **線の色**。コマンド `\arrayrulecolor` これに使います。例では HTML 形式を使用していますが、ほかの形式も利用できます。完全な一覧は xcolor のドキュメントを参照してください（リンクは～の [参考資料](#further-reading) セクションにあります）。
* **セルの背景色**。コマンドを使います `\cellcolor`。波括弧内に名前を直接入力する（red、gray、green など）か、角括弧内に形式パラメータを渡し（例では HTML）、その形式に従って波括弧内で希望の色を設定できます。
* **行の背景色**。この場合 `\rowcolor` で実現できます。色の選択については、前の 2 つのコマンドで述べたのと同じことが、このコマンドにも当てはまります。
* **列の背景色**。これは少し厄介ですが、最も簡単なのは新しい列型を定義することです。コマンド

  ```latex
  \newcolumntype{s}{>{\columncolor[HTML]{AAACED}} p{3cm}}
  ```

  は、という列型を定義します `s` その配置は `p`、列幅は `3cm` 、色は HTML 形式で `AAACED`に設定されます。この新しい列型は～で使われています `tabular` 環境内で。

## リファレンスガイド

～におけるパラメータの簡単な説明 `tabular` 環境内で。

表は `tabular` 環境内で。

```
\begin{tabular}[pos]{cols}
 表の内容
\end{tabular}
```

ここで指定できるオプションは次のとおりです:

* **`pos`** : 縦位置。次の値を取ることができます:

|              |                            |
| ------------ | -------------------------- |
| `t`          | 上端の線がテキストのベースラインに揃います      |
| `b`          | 下端の線がテキストのベースラインに揃います      |
| `c` または none | 表がテキストのベースラインに対して中央揃えになります |

* **`cols`** : 各列の配置と罫線を定義します。次の値を取ることができます:

|                |                                                             |
| -------------- | ----------------------------------------------------------- |
| `l`            | 左揃えの列                                                       |
| `c`            | 中央揃えの列                                                      |
| `r`            | 右揃えの列                                                       |
| `p{'width'}`   | テキストが上揃えの段落列                                                |
| `m{'width'}`   | テキストが中央揃えの段落列（～が必要 `array` パッケージにあります）                      |
| `b{'width'}`   | テキストが下揃えの段落列（～が必要 `array` パッケージにあります）                       |
| `\|`           | 縦線                                                          |
| `\|\|`         | 二重縦線                                                        |
| `*{num}{form}` | 書式が繰り返されます *num* 回。たとえば `*{3}{\|l}\|` は次と等価です `\|l\|l\|l\|` |

セルを区切ったり改行を入れたりするには、次のコマンドを使います:

|               |                                                     |
| ------------- | --------------------------------------------------- |
| `&`           | 列区切り                                                |
| `\\`          | 新しい行を開始（後ろに追加スペースを指定可能 `\\` 角括弧を使って、たとえば `\\[6pt]`) |
| `\\hline`     | 行間の横線                                               |
| `\newline`    | セル内で新しい行を開始（段落列内）                                   |
| `\cline{i-j}` | 列から始まる部分横線 *i* 列で終わる *j*                            |

## さらに読む

詳細については

* [Overleaf で表を挿入する方法](/latex/ja/narejjibsu/067-how-to-generate-and-insert-latex-tables-in-overleaf.md)
* [画像と表の配置](/latex/ja/to/02-positioning-images-and-tables.md)
* [表と図の一覧](/latex/ja/to/03-lists-of-tables-and-figures.md)
* [LaTeX における長さ](/latex/ja/shu-shi-she-ding/01-lengths-in-latex.md)
* [LaTeXで色を使う](/latex/ja/shu-shi-she-ding/13-using-colors-in-latex.md)
* [xcolor パッケージマニュアル](http://mirrors.ctan.org/macros/latex/contrib/xcolor/xcolor.pdf)
* [tabularx パッケージマニュアル](https://texdoc.org/pkg/tabularx)
* [longtableパッケージのマニュアル](http://mirrors.ctan.org/macros/latex/required/tools/longtable.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/to/01-tables.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.
