> 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/shu-shi-she-ding/03-page-numbering.md).

# ページ番号

文書のページ番号は、特定の *style*、たとえばアラビア数字やローマ数字を用いて、特定のページの *位置*—通常はヘッダーまたはフッター内です。この記事では、ページ番号のスタイルと位置を変更する方法を示します：

* その *style* ページ番号の書式は、 `\pagenumbering` コマンド;
* その *位置* ページ番号の位置は、 [`fancyhdr` パッケージ](https://ctan.org/pkg/fancyhdr?lang=en).

## ページ番号のスタイルを設定する

ページ番号のスタイルは、次のコマンドで変更できます

```latex
\pagenumbering{⟨style⟩}
```

ここで `⟨style⟩` の1つです

* `arabic`：アラビア数字（1, 2, 3, ...）を使用します
* `alph`：小文字のアルファベット（a, b, c, ...）を使用します
* `Alph`：大文字のアルファベット（A, B, C, ...）を使用します
* `roman`：小文字のローマ数字（i, ii, iii, ...）を使用します
* `Roman`：大文字のローマ数字（I, II, III, ...）を使用します

### ページ番号のスタイルを示す例

次の例では、目次に続いて5ページを組版し、それぞれのページでページ番号の `⟨style⟩` オプションの1つを示します。内部的には、LaTeXは、いわゆる *カウンター* を使って現在のページ番号を記録します。カウンターとは、整数値を格納するために使われるLaTeX変数の名前です。詳しくは [OverleafのCounters記事](/latex/ja/shu-shi-she-ding/10-counters.md) をご覧ください。

```latex
\begin{document}
% 目次を挿入
\tableofcontents
\newpage
\section{大文字ローマ数字}
\pagenumbering{Roman}% 大文字の 'R'：大文字ローマ数字
\blindtext[1]
\newpage
\section{小文字ローマ数字} % 小文字のローマ数字
\pagenumbering{roman}
\blindtext[1]
\newpage
\section{アラビア数字}
\pagenumbering{arabic} % アラビア/インド数字のページ番号
\blindtext[1]
\newpage
\section{小文字アルファベット}
\pagenumbering{alph} % 小文字アルファベットのページ「番号」
\blindtext[1]
\newpage
\section{大文字アルファベット}
\pagenumbering{Alph} % 大文字アルファベットのページ「番号」
\blindtext[1]
\end{document}
```

[Overleaf でこの例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+page+number+styles\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Use+a+small+page+size+to+avoid+%0A%25+needing+lots+of+text+to+create+%0A%25+several+pages%0A%5Cusepackage%5Bincludefoot%2C%0Apaperheight%3D10cm%2C%0Apaperwidth%3D10cm%2C%0Atextwidth%3D9cm%2C%0Atextheight%3D8cm%5D%7Bgeometry%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Insert+a+table+of+contents%0A%5Ctableofcontents%0A%5Cnewpage%0A%5Csection%7BUppercase+Roman%7D%0A%5Cpagenumbering%7BRoman%7D%25+Capital+%27R%27%3A+uppercase+Roman+numerals%0A%5Cblindtext%5B1%5D%0A%5Cnewpage%0A%5Csection%7BLowercase+Roman%7D+%25+lowercase+Roman+numerals%0A%5Cpagenumbering%7Broman%7D%0A%5Cblindtext%5B1%5D%0A%5Cnewpage%0A%5Csection%7BArabic+numbers%7D%0A%5Cpagenumbering%7Barabic%7D+%25+Arabic%2FIndic+page+numbers%0A%5Cblindtext%5B1%5D%0A%5Cnewpage%0A%5Csection%7BLowercase+alphabetic%7D%0A%5Cpagenumbering%7Balph%7D+%25+Lowercase+alphabetic+page+%22numbers%22%0A%5Cblindtext%5B1%5D%0A%5Cnewpage%0A%5Csection%7BUppercase+alphabetic%7D%0A%5Cpagenumbering%7BAlph%7D+%25+Uppercase+alphabetic+page+%22numbers%22%0A%5Cblindtext%5B1%5D%0A%5Cend%7Bdocument%7D)

次の図は、この文書で作成された目次を示しています。 `\pagenumbering` コマンドが各スタイルごとに開始ページ番号を初期値にリセットしていることに注目してください： `i` の `roman` スタイル、 `ある` の `Alph` スタイル、 `I` の `Roman` スタイル、以下同様です：

![LaTeXで組版した目次の例](/files/342d59d27c0779a56be767b5a68d94050d01c8a1)

この例で生成されたサンプルページを2つ示します。1枚目の画像はページ番号を大文字のローマ数字で、2枚目はページ番号を大文字のアルファベットで表示しています：

![ローマ数字で組版したページ番号の例](/files/4869ee2ca67f71aec5f30ef6948f525c24ec96e3)

![大文字のアルファベットで組版したページ番号の例](/files/ba9da2ecaebff2c384f6205f2f728091747721cc)

## bookクラス：2種類のページ番号スタイルを使う

この [本の最初の数ページ](https://en.wikipedia.org/wiki/Book_design#Structure)、これには著作権ページ、タイトルページまたは半タイトルページ、前書きやまえがき、目次が含まれます）は、まとめて *前付けの* ページ、または略して prelims と呼ばれます—これらのページを指す別の用語は [*前付け*](https://en.wikipedia.org/wiki/Book_design#Front_matter)です。伝統的に、前付けのページは小文字のローマ数字で番号付けされ、本体ページはアラビア数字で番号付けされます。 `book` documentクラスにはこれを支援するコマンドが用意されており、次の例が示しています。

```latex
\documentclass{book}
% emptypage パッケージはページ番号と
% 見出しが空白ページに表示されるのを防ぎます。
\usepackage{emptypage}
\begin{document}
\frontmatter % ページ番号に小文字のローマ数字を使用
\chapter*{序文}
\addcontentsline{toc}{chapter}{序文}
序文は、その本の著者ではない人が書きます。

\chapter*{まえがき}
\addcontentsline{toc}{chapter}{まえがき}
まえがきは本の著者が書きます。

\tableofcontents

\mainmatter % ここからページ番号にアラビア数字を使用

\chapter{第1章}
ここは空の章になります...
\section{最初の節}
本文が少しあるとよいでしょう。
\chapter{第2章}
\end{document}
```

[Overleaf でこの例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+page+numbers+in+book+class\&snip=%5Cdocumentclass%7Bbook%7D%0A%25+The+emptypage+package+prevents+page+numbers+and%0A%25+headings+from+appearing+on+empty+pages.%0A%5Cusepackage%7Bemptypage%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cfrontmatter+%25Use+lowercase+Roman+numerals+for+page+numbers%0A%5Cchapter%2A%7BForeword%7D%0A%5Caddcontentsline%7Btoc%7D%7Bchapter%7D%7BForeword%7D%0AThe+Foreword+is+written+by+someone+who+is+not+the+book%27s+author.%0A%0A%5Cchapter%2A%7BPreface%7D%0A%5Caddcontentsline%7Btoc%7D%7Bchapter%7D%7BPreface%7D%0AThe+Preface+is+written+by+the+book%27s+author.%0A%0A%5Ctableofcontents%0A%0A%5Cmainmatter+%25+Now+Use+Arabic+numerals+for+page+numbers%0A%0A%5Cchapter%7BFirst+Chapter%7D%0AThis+will+be+an+empty+chapter...%0A%5Csection%7BFirst+section%7D%0ASome+text+would+be+good.%0A%5Cchapter%7BThe+second+chapter%7D%0A%5Cend%7Bdocument%7D)

この例で作成される目次は、前付けにローマ数字、本体にアラビア数字を使うことを示しています：

![本でローマ数字とアラビア数字のページ番号を表示する](/files/5201466115384a3fbbf75ea0ae6396db3f36e882)

ページ番号を制御するコマンドは次のとおりです：

* `\frontmatter`：このコマンドの後から、次のコマンドの前までのページは `\mainmatter`小文字のローマ数字で番号付けされます。
* `\mainmatter`：これによりページカウンターが再開され、スタイルがアラビア数字に変わります。

## articleクラス：2種類のページ番号スタイルを使う

前述のとおり、現在のページ番号は [LaTeXのカウンター変数](/latex/ja/shu-shi-she-ding/10-counters.md#introduction-to-latex-counters) と呼ばれる `page`に格納されています。 `page`、または他のどのカウンター変数も、次のコマンドを使って特定の値に設定できます `\setcounter` コマンド：

```latex
\setcounter{⟨countvar⟩}{⟨intval⟩}
```

ここでカウンター変数 `⟨countvar⟩` は次の値に設定されます `⟨intval⟩`。たとえば、 `page` カウンターを `3` に設定するには、次のように書きます

```latex
\setcounter{page}{3}
```

カウンター変数を変更するための他のコマンドには `\addtocounter` や `\stepcounter`:

```latex
\addtocounter{⟨countvar⟩}{⟨increment⟩}
\stepcounter{⟨countvar⟩}
```

* `\addtocounter{⟨countvar⟩}{⟨increment⟩}` 増分を追加します `⟨increment⟩` をカウンター変数に `⟨countvar⟩`. **注**: `⟨increment⟩` 加える値は正でも負でも構いません。正ならカウンター値を増やし、負なら減らします。
* `\steptocounter{⟨countvar⟩}` カウンター変数に 1 を加えます `⟨countvar⟩`

この仮想的な例では、まだ書かれていない節やページ数が見積もられている節を含む目次を計画するために、ページカウンターを変更します。また、 `\pagenumbering{roman}` や `\pagenumbering{Arabic}` ページ番号のスタイルを設定するために使います。

```latex
\documentclass{article}
\pagenumbering{roman}
\begin{document}

\section*{ゲスト序文（未定）}
\addcontentsline{toc}{section}{序文：4ページ（未定）}
執筆予定：4ページ分。
\newpage
\setcounter{page}{5}

\section*{導入（2ページ）}
\addcontentsline{toc}{section}{導入：2ページ（未定）}
執筆予定：2ページ分。
\newpage
\addtocounter{page}{1}

\section*{戦略概要（2ページ）}
\addcontentsline{toc}{section}{戦略概要：2ページ（未定）}
執筆予定：2ページ。
\newpage
\stepcounter{page}

\tableofcontents

\newpage
\pagenumbering{arabic}

\section{第1レベル見出し}
このページの本文。
\newpage
\section{別の第1レベル見出し}
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Mixing+page+number+formats+in+the+article+class\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cpagenumbering%7Broman%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Csection%2A%7BGuest+Foreword+%28TBD%29%7D%0A%5Caddcontentsline%7Btoc%7D%7Bsection%7D%7BForeword%3A+4+pages+%28TBD%29%7D%0ATo+be+written%3A+Allowing+4+pages.%0A%5Cnewpage+%0A%5Csetcounter%7Bpage%7D%7B5%7D%0A%0A%5Csection%2A%7BIntroduction+%282+pages%29%7D%0A%5Caddcontentsline%7Btoc%7D%7Bsection%7D%7BIntroduction%3A+2+pages+%28TBD%29%7D%0ATo+be+written%3A+2+pages+allowed.%0A%5Cnewpage%0A%5Caddtocounter%7Bpage%7D%7B1%7D%0A%0A%5Csection%2A%7BStrategy+summary+%282+pages%29%7D%0A%5Caddcontentsline%7Btoc%7D%7Bsection%7D%7BStrategy+summary%3A+2+pages+%28TBD%29%7D%0ATo+be+written%3A+2+pages.%0A%5Cnewpage%0A%5Cstepcounter%7Bpage%7D%0A%0A%5Ctableofcontents%0A%0A%5Cnewpage%0A%5Cpagenumbering%7Barabic%7D%0A%0A%5Csection%7BLevel+1+heading%7D%0ASome+text+on+this+page.%0A%5Cnewpage%0A%5Csection%7BAnother+Level+1+heading%7D%0A%5Cend%7Bdocument%7D)

この例では、次の目次が生成され、 `page` カウンターの値を変更した結果が示されます：

![LaTeXでページカウンターを変更する](/files/4f427bca2cd7d799b91d8382e2d6ef7f3e47956e)

## fancyhdrパッケージでページ番号をカスタマイズする

この `fancyhdr` パッケージは、ページ番号の位置と形式をカスタマイズするために使えます。たとえば、ヘッダーやフッター内の特定の位置に配置できます。Overleafの記事 [ヘッダーとフッター](/latex/ja/shu-shi-she-ding/02-headers-and-footers.md) ではこれについて詳しく解説していますが、ここでは多数の例を再掲しません。

ここでは、総ページ数に対する現在のページ番号を書き出す例を1つ示します。たとえば `Yページ中のXページ` ここで Y は、次のコマンドで取得した文書の総ページ数です [`lastpage` パッケージ](https://ctan.org/pkg/lastpage?lang=en).

```latex
\documentclass{article}
% 小さめのページサイズを使って
% 多くの本文が必要にならないように
% 複数ページを作成する
\usepackage[includefoot,
paperheight=10cm,
paperwidth=10cm,
textwidth=9cm,
textheight=8cm]{geometry}
\usepackage{blindtext}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % 既存のヘッダー/フッター項目を消去
% ページ X / Y を右側の
% フッターに
\fancyfoot[R]{\thepage\hspace{1pt}ページ / \pageref{LastPage}}
\begin{document}
% 目次を挿入
\tableofcontents
\newpage
\section{1}
\blindtext[1]
\newpage
\section{2}
\blindtext[1]
\newpage
\section{3}
\blindtext[1]
\newpage
\section{4}
\blindtext[1]
\newpage
\section{5}
\blindtext[1]
\end{document}
```

[この例を Overleaf で開く。](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Modifying+page+numbers+with+fancyhdr\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Use+a+small+page+size+to+avoid+%0A%25+needing+lots+of+text+to+create+%0A%25+several+pages%0A%5Cusepackage%5Bincludefoot%2C%0Apaperheight%3D10cm%2C%0Apaperwidth%3D10cm%2C%0Atextwidth%3D9cm%2C%0Atextheight%3D8cm%5D%7Bgeometry%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cusepackage%7Blastpage%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cpagestyle%7Bfancy%7D%0A%5Cfancyhf%7B%7D+%25+clear+existing+header%2Ffooter+entries%0A%25+Place+Page+X+of+Y+on+the+right-hand%0A%25+side+of+the+footer%0A%5Cfancyfoot%5BR%5D%7BPage+%5Cthepage+%5Chspace%7B1pt%7D+of+%5Cpageref%7BLastPage%7D%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Insert+a+table+of+contents%0A%5Ctableofcontents%0A%5Cnewpage%0A%5Csection%7BOne%7D%0A%5Cblindtext%5B1%5D%0A%5Cnewpage%0A%5Csection%7BTwo%7D%0A%5Cblindtext%5B1%5D%0A%5Cnewpage%0A%5Csection%7BThree%7D%0A%5Cblindtext%5B1%5D%0A%5Cnewpage%0A%5Csection%7BFour%7D%0A%5Cblindtext%5B1%5D%0A%5Cnewpage%0A%5Csection%7BFive%7D%0A%5Cblindtext%5B1%5D%0A%5Cend%7Bdocument%7D)

次の画像は、この例で生成されたページの1つを示しています—注目してください `6ページ中の3ページ` フッターの右側に:

![fancyhdrでページ番号を変更する](/files/93136aa5b7e49fa89690146d7038d1fad7bd0c89)


---

# 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/shu-shi-she-ding/03-page-numbering.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.
