> 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/02-headers-and-footers.md).

# ヘッダーとフッター

## はじめにと概要

この記事では、ドキュメントのヘッダーとフッターを変更する方法を、 [fancyhdr パッケージを使って](https://ctan.org/pkg/fancyhdr?lang=en)。ヘッダーとフッターをカスタマイズする別の方法については、付随記事で取り上げています。 [*LaTeX はどのようにヘッダーとフッターを組版するのですか？*](/latex/ja/xiang-xi-ji-shi/23-how-does-latex-typeset-headers-and-footers.md)、LaTeX のコードをさらに掘り下げて新しいページスタイルを定義したり、適切な低レベルのコマンドを再定義したりすることです。

ここでは、文書内で使われる既定のヘッダーとフッターを定義する、LaTeX の基本機能のいくつかを概観することから始めます。

* [文書クラス](#document-classes)
* [LaTeX のページスタイル](#latex-page-styles)

導入部分を飛ばしたい場合は、 [のセクションへ進んでください。 `fancyhdr` パッケージ](#using-the-fancyhdr-package)。前述のとおり、はるかに技術的な詳細は付随記事に含まれています。 [*LaTeX はどのようにヘッダーとフッターを組版するのですか？*](/latex/ja/xiang-xi-ji-shi/23-how-does-latex-typeset-headers-and-footers.md) そこでは、TeX エンジンがヘッダーとフッターを作成するために使う、マークに基づく低レベルの仕組みを説明し、その理由についても解説しています。 `\mark` コマンドが必要になるのかを説明しています。

### LaTeX の文書クラス

さまざまな種類の LaTeX 文書は、 *文書クラス*を使って作成されます。たとえば、LaTeX にはいくつかの標準クラスがあります。

* `book`
* `レポート`
* `article`
* `letter`

は、 `\documentclass` コマンド：

```latex
\documentclass[⟨options⟩]{⟨class⟩}
```

次のとおりです：

* `⟨class⟩` は標準タイプのいずれか（`book`, `レポート`, `article`, `letter`）であってもよく、または [個人や機関が提供したものでもかまいません](https://www.ctan.org/topic/class).
* `⟨options⟩` は文書の特定のインスタンスを設定するために使う設定です `⟨class⟩`。利用可能な `⟨options⟩` は、 `⟨class⟩` によって異なります。

#### 片面文書と両面文書

LaTeX 文書クラスが、左向きページ（偶数ページ番号）と右向きページ（奇数ページ番号）で異なるレイアウトをサポートしている場合、文書のヘッダーとフッターは通常、左向きページと右向きページで異なります。標準文書クラスの既定値は次のとおりです。

* `book`: 両面
* `article` や `レポート`: 片面だが、オプション `twoside`を使って設定できます。例えば:

```latex
\documentclass[twoside]{article}
```

または

```latex
\documentclass[twoside]{report}
```

#### 文書クラスの既定の⟨options⟩

LaTeX は、標準文書クラスごとに一連の既定 `⟨options⟩` を適用します。

* `article`: 既定 `⟨options⟩` すでに `letterpaper,10pt,oneside,onecolumn,final`
* `レポート`: 既定 `⟨options⟩` すでに `letterpaper,10pt,oneside,onecolumn,final,openany`
* `book`: 既定 `⟨options⟩` すでに `letterpaper,10pt,twoside,onecolumn,final,openright`
* `letter`: 既定 `⟨options⟩` すでに `letterpaper,10pt,oneside,onecolumn,final`

文書クラスはまた、文書を部、章、節、小節などの論理的な区分へ構造化するためのコマンドも提供します。予想されるように、 `book` クラスには豊富な文書構造化コマンドがあります。

### LaTeX のページスタイル

LaTeX では、文書のヘッダーとフッターの既定の形式は、使用されている *ページスタイル* によって決まります。LaTeX にはいくつかの定義済みページスタイルがあります。

* `空`: ページにヘッダーもフッターもない
* `plain`: ページヘッダーはなく、フッターは中央揃えのページ番号のみ
* `見出し`: フッターはなく、ヘッダーにはクラス固有の情報とページ番号が含まれる
* `myheadings`: フッターはなく、ヘッダーにはページ番号とユーザーが指定した情報が含まれる

#### 標準文書クラスの既定ページスタイル

ユーザーが別途指定しない限り、標準文書クラスは既定のページスタイルを適用します。

* その `article` や `レポート` クラスは `plain`
* その `book` クラスは `見出し`

#### ページスタイルの設定

コア LaTeX には、ページスタイルを変更（設定）するための 2 つのコマンドがあります。

* `\pagestyle{⟨style⟩}`: 現在のページとそれ以降のすべてのページのスタイルを `⟨style⟩`
* `\thispagestyle{⟨style⟩}`: 現在のページだけのスタイルを `⟨style⟩`

ページ番号のスタイルはコマンド `\pagenumbering{⟨numberstyle⟩}`で設定します。たとえば、 `\pagenumbering{roman}` はページ番号を小文字のローマ数字で組版します: i, ii, iii...

### LaTeX のページレイアウト

ヘッダーとフッターは全体のページレイアウト／デザインの一部なので、LaTeX のページレイアウトモデルについて少し理解しておくと役立ちます。以下の Overleaf 記事が参考になるでしょう。

* LaTeX のページレイアウト入門として、Overleaf の記事 [ページサイズと余白](/latex/ja/shu-shi-she-ding/07-page-size-and-margins.md) を使う方法を示しています [**`geometry`** パッケージ](https://ctan.org/pkg/geometry?lang=en);
* より詳しい説明が必要なら、次の記事をおすすめします [LaTeX のページレイアウトパラメータのビジュアルガイド](/latex/ja/xiang-xi-ji-shi/04-a-visual-guide-to-latex-s-page-layout-parameters.md).

### 標準 LaTeX 文書クラスとページスタイルにおけるヘッダーとフッター

前述のとおり、LaTeX はいくつかの [組み込みページスタイル](#latex-page-styles) を標準文書クラスの既定として提供しています。以下の短い例では、LaTeX の既定 `⟨options⟩` を用いて標準文書クラスが生成する既定のヘッダーとフッターを示します。

#### article クラスの既定ヘッダーとフッター

```latex
\documentclass{article}
% 便利な小さめのページサイズを選択
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=10cm]{geometry}
\usepackage{lipsum}% ダミーテキスト用
\title{article クラスの例}
\author{Overleaf}
\begin{document}
\maketitle

\section{はじめに...}
\lipsum[2]

\section{別の節}
\lipsum[1]

\section{さらに別の}
\lipsum[1]
```

[この **`article`** の例（Overleaf）](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=An+article+class+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D10cm%5D%7Bgeometry%7D%0A%5Cusepackage%7Blipsum%7D%25+for+some+dummy+text%0A%5Ctitle%7BAn+article+class+example%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%0A%5Csection%7BIn+the+beginning...%7D%0A%5Clipsum%5B2%5D%0A%0A%5Csection%7BAnother+section%7D%0A%5Clipsum%5B1%5D%0A%0A%5Csection%7BYet+another%7D%0A%5Clipsum%5B1%5D%0A%5Cend%7Bdocument%7D)

#### report クラスの既定ヘッダーとフッター

```latex
\documentclass{report}
% 便利な小さめのページサイズを選択
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=10cm]{geometry}
\usepackage{lipsum}% ダミーテキスト用
\title{report クラスの例}
\author{Overleaf}
\begin{document}
\maketitle
\chapter{第1章}
\section{はじめに...}
\lipsum[2]

\section{別の節}
\lipsum[1]

\section{さらに別の}
\lipsum[1]
```

[この **`レポート`** の例（Overleaf）](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=A+report+class+example\&snip=%5Cdocumentclass%7Breport%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D10cm%5D%7Bgeometry%7D%0A%5Cusepackage%7Blipsum%7D%25+for+some+dummy+text%0A%5Ctitle%7BA+report+class+example%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%5Cchapter%7BOne%7D%0A%5Csection%7BIn+the+beginning...%7D%0A%5Clipsum%5B2%5D%0A%0A%5Csection%7BAnother+section%7D%0A%5Clipsum%5B1%5D%0A%0A%5Csection%7BYet+another%7D%0A%5Clipsum%5B1%5D%0A%5Cend%7Bdocument%7D)

#### book クラスの既定ヘッダーとフッター

```latex
\documentclass{book}
% 便利な小さめのページサイズを選択
\usepackage[paperheight=16cm,paperwidth=12cm,textwidth=10cm]{geometry}
\usepackage{lipsum}% ダミーテキスト用
\title{\TeX{} ユーザーの回想録}
\author{Overleaf}
\begin{document}

\frontmatter
\maketitle
これはローマ数字を使う frontmatter です。

\mainmatter
\chapter{どこから始めるか}
\lipsum[4]

\section{はじめに...}
\lipsum[1]

\section{さらに別の節}
\lipsum[1]

\chapter{私が覚えていること}

\section{ああ、それからさらに別の節}
\lipsum[1]
```

[この **`book`** の例（Overleaf）](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=A+book+class+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D10cm%5D%7Bgeometry%7D%0A%5Cusepackage%7Blipsum%7D%25+for+some+dummy+text%0A%5Ctitle%7BMemoirs+of+a+%5CTeX%7B%7D+user%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cfrontmatter%0A%5Cmaketitle%0AThis+is+frontmatter+which+uses+Roman+numerals.%0A%0A%5Cmainmatter%0A%5Cchapter%7BWhere+do+I+start%7D%0A%5Clipsum%5B4%5D%0A%0A%5Csection%7BIn+the+beginning...%7D%0A%5Clipsum%5B1%5D%0A%0A%5Csection%7BYet+another+section%7D%0A%5Clipsum%5B1%5D%0A%0A%5Cchapter%7BThings+I+remember%7D%0A%0A%5Csection%7BOh+and+a+further+section%7D%0A%5Clipsum%5B1%5D%0A%5Cend%7Bdocument%7D)

### 「標準ではない」LaTeX 文書クラスでヘッダーとフッターを変更する

ヘッダーとフッターを変更するために必要なパッケージ／コマンドは、使用する文書クラスによって異なる場合があります。たとえば、 [TeX FAQ では](https://texfaq.org/FAQ-fancyhdr#:~:text=The%20scrlayer%2Dscrpage%20package%20provides,and%20has%20several%20predefined%20styles) の使用について述べています [scrlayer-scrpage](https://ctan.org/pkg/scrlayer-scrpage?lang=en) パッケージを、 [fancyhdr](https://ctan.org/pkg/fancyhdr?lang=en)ではなく、 [KOMA-script 文書クラス](https://ctan.org/pkg/koma-script)との統合を改善するために使用します。さらに、 [memoir 文書クラス](https://ctan.org/pkg/memoir?lang=en) には、ヘッダーとフッターを変更するための独自機能（ユーザーコマンド）があります。

## fancyhdr パッケージの使用

を読み込むには、 `fancyhdr` パッケージを文書のプリアンブルに次の行を追加します。

```latex
\usepackage[⟨options⟩]{fancyhdr}
```

ここで `⟨options⟩` は、 [パッケージのドキュメント](http://mirrors.ctan.org/macros/latex/contrib/fancyhdr/fancyhdr.pdf).

### fancyhdr のヘッダーとフッターの構造

以下の図は、 `fancyhdr` によって定義されるヘッダーとフッターの一般的な構造を、両面文書について要約したものです。

* ヘッダーとフッターには、左（偶数）ページと右（奇数）ページで異なる内容を含めることができます
* ヘッダーとフッターは 3 つの「ゾーン」に分かれています
  * **L***eft*
  * **C***entre*
  * **R***ight*
* ヘッダーとフッターには任意のルール（線）を含めることができます

その **L** ゾーンでは内容は左揃えで組版され、 **C** ゾーンでは中央揃えになり、 **R** ゾーンでは右揃えで組版されます。

![fancyhdr のヘッダーとフッターの構造を示す図](/files/e16c407557681a5efa31dfbc90c85a4da42bb17f)

によって提供されるコマンド `fancyhdr` は、特定のヘッダー／フッターのゾーンとページ位置を識別するために、「座標」と呼ばれる 1 文字の略号を使います。

* **`O`** または **`E`**: \*\*`O`\*\*odd または \*\*`E`\*\*even ページを指定するため
* **`H`** または **`F`**: \*\*`H`\*\*header または \*\*`F`\*\*footer を示すため
* **`L`**, **`C`** または **`R`**: ヘッダーまたはフッターの \*\*`L`\*\*left, \*\*`C`\*\*centre, そして \*\*`R`\*\*right の「ゾーン」に対して

### コマンドの紹介

このセクションでは、 `fancyhdr` ヘッダーとフッターの内容を定義するために使ういくつかの

* `\fancyhead[*locations*]{*content*}`
* `\fancyfoot[*locations*]{*content*}`
* `\fancyhf[*locations*]{*content*}`

これらの各コマンドは、「座標」を使ってヘッダーとフッターの `*locations*` ここで `*content*` がどこに現れるかを定義します。使うコマンドによって、目的の `*locations*`.

#### 最大 2 座標を使うコマンド

以下のコマンドは、ヘッダーまたはフッター内の特定の位置を指定するために最大 2 座標を必要とします。

* `\fancyhead[*locations*]{*content*}`: は、 `**H**`eader の座標
* `\fancyfoot[*locations*]{*content*}`: は、 `**F**`ooter の座標

ここで `*locations*` は、1 つまたは 2 つの座標で指定される位置の、任意のカンマ区切りリストで、その中に `*content*`.

**両面文書の例**

以下の例は、 `fancyhdr` の文書から引用しています。

```latex
\documentclass{book}
\usepackage[paperheight=16cm, paperwidth=12cm,% 用紙の高さと幅を設定
includehead,
nomarginpar,% 余白段落は不要
textwidth=10cm,% \textwidth を 10cm に設定
headheight=10mm,% \headheight を 10mm に設定
]{geometry}
\usepackage{fancyhdr}
\begin{document}
% ページスタイルを「fancy」に設定...
\pagestyle{fancy}
%...  سپس設定する。
\fancyhead{} % すべてのヘッダーフィールドをクリア
\fancyhead[RO,LE]{\textbf{新卒者の実績}}
\fancyfoot{} % すべてのフッターフィールドをクリア
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[LO,CE]{差出人: K. Grant}
\fancyfoot[CO,RE]{宛先: Dean A. Smith}
% いくつかの内容:
これは 1 ページ目です。\newpage
これは 2 ページ目です。
\end{document}
```

[この `fancyhdr` Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=fancyhdr+package+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%25...+then+configure+it.%0A%5Cfancyhead%7B%7D+%25+clear+all+header+fields%0A%5Cfancyhead%5BRO%2CLE%5D%7B%5Ctextbf%7BThe+performance+of+new+graduates%7D%7D%0A%5Cfancyfoot%7B%7D+%25+clear+all+footer+fields%0A%5Cfancyfoot%5BLE%2CRO%5D%7B%5Cthepage%7D%0A%5Cfancyfoot%5BLO%2CCE%5D%7BFrom%3A+K.+Grant%7D%0A%5Cfancyfoot%5BCO%2CRE%5D%7BTo%3A+Dean+A.+Smith%7D%0A%25+Some+content%3A%0AThis+is+page+1.%5Cnewpage%0AThis+is+page+2.%0A%5Cend%7Bdocument%7D)

次の図は、この例で生成される出力を示しています。

![LaTeX fancyhdr パッケージで作成した両面文書の例](/files/e9a5f09a95c6cdbc1bf563140fee19cacbf07744)

**使用されているコマンドに関する注意**

* **`\fancyhead{}`**: ヘッダーの設定を消去します
* **`\fancyfoot{}`**: フッターの設定を消去します
* **`\fancyhead[RO,LE]{\textbf{新卒者の実績}}`**: ヘッダーの位置 **`RO`** (\*\*`R`**ight**`O`**dd）と `LE` (**`L`**eft**`E`ven）を使って内容を配置します `\textbf{新卒者の実績}`
* **`\fancyfoot[LE,RO]{\thepage}`**: フッターの位置 **`LE`** (\*\*`L`**eft**`E`**ven）と `RO` (**`R`**ight**`O`dd）を使って、\thepage によって出力されるページ番号を配置します `\thepage`
* **`\fancyfoot[LO,CE]{差出人: K. Grant}`**: フッターの位置 **`LO`** (\*\*`L`**eft**`O`**dd）と `CE` (**`C`**entre**`E`ven）を使って内容を配置します `差出人: K. Grant`
* **`\fancyfoot[CO,RE]{宛先: Dean A. Smith}`**: フッターの位置 **`CO`** (\*\*`C`**entre**`O`**dd）と `RE` (**`R`**ight**`E`ven）を使って内容を配置します `宛先: Dean A. Smith`

**片面文書と両面文書**

この [上の図](#hfstructure) は、 `book` クラスのような両面文書のヘッダーとフッターの構造を示しています。 `article`/`レポート` クラス、または `twoside`.

**オプションを使って読み込まれたクラス**

〜については *片面* に基づく文書では、すべてのページは実質的に右ページなので、 `article` または `レポート` のための「座標」は `**E**`偶数ページには適用されません。また、 *必要が* を指定する必要もありませ `**O**` んし、1 つの `**L**`, `**C**` または `**R**` の値だけを使うことができます。

```latex
\documentclass{article}
\usepackage[paperheight=16cm, paperwidth=12cm,% 用紙の高さと幅を設定
includehead,
nomarginpar,% 余白段落は不要
textwidth=10cm,% \textwidth を 10cm に設定
headheight=10mm,% \headheight を 10mm に設定
]{geometry}
\usepackage{fancyhdr}
\begin{document}
% ページスタイルを「fancy」に設定...
\pagestyle{fancy}
\title{片面文書}
\author{Overleaf}
\date{2022年8月}
\fancyhf{} % 既存のヘッダー/フッター項目を消去
% O 座標を指定する必要はありません
\fancyhead[R]{Hello}
\fancyfoot[L]{\thepage}
\maketitle
\section{導入}
いくつかの内容。
\newpage
\section{続き...}
\end{document}
```

[この `fancyhdr` Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Single-sided+fancyhdr+package+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%5Ctitle%7BSingle-sided+document%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BAugust+2022%7D%0A%5Cfancyhf%7B%7D+%25+clear+existing+header%2Ffooter+entries%0A%25+We+don%27t+need+to+specify+the+O+coordinate%0A%5Cfancyhead%5BR%5D%7BHello%7D%0A%5Cfancyfoot%5BL%5D%7B%5Cthepage%7D%0A%5Cmaketitle%0A%5Csection%7BIntroduction%7D%0ASome+content.%0A%5Cnewpage%0A%5Csection%7BContinued...%7D%0A%5Cend%7Bdocument%7D)

この `fancyhdr` パッケージは、片面文書で `**E**` 座標を使ってヘッダーやフッターを指定しようとすると警告を出します。

```latex
\documentclass{article}
\usepackage[paperheight=16cm, paperwidth=12cm,% 用紙の高さと幅を設定
includehead,
nomarginpar,% 余白段落は不要
textwidth=10cm,% \textwidth を 10cm に設定
headheight=10mm,% \headheight を 10mm に設定
]{geometry}
\usepackage{fancyhdr}
\begin{document}
% ページスタイルを「fancy」に設定...
\pagestyle{fancy}
\title{twoside なしの警告}
\author{Overleaf}
\date{2022年7月}
\fancyhead[E]{Hello}% これは警告を引き起こします！
\fancyfoot[E]{\thepage}% これは警告を引き起こします！
\maketitle
\section{導入}
いくつかの内容。
\newpage
\section{続き...}
\end{document}
```

[この ***誤りのある*** `fancyhdr` Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=fancyhdr+package+warning+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%5Ctitle%7BWarning+without+twoside%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BJuly+2022%7D%0A%5Cfancyhead%5BE%5D%7BHello%7D%25+This+triggers+a+warning%21%0A%5Cfancyfoot%5BE%5D%7B%5Cthepage%7D%25+This+triggers+a+warning%21%0A%5Cmaketitle%0A%5Csection%7BIntroduction%7D%0ASome+content.%0A%5Cnewpage%0A%5Csection%7BContinued...%7D%0A%5Cend%7Bdocument%7D)

この注釈付きスクリーングラブで見られるように、

![fancyhdr パッケージからの警告例](/files/111ee640700d424b48b83fee9a293add715f3542)

上の例では次の警告が出力されます。

```latex
Package fancyhdr Warning: \fancyhead's `E' option without twoside option is useless on input line 23.
Package fancyhdr Warning: \fancyfoot's `E' option without twoside option is useless on input line 24.
```

**両面文書で単一の座標を使う: E と O を省略する**

もし `\fancyhead` または `\fancyfoot` を両面文書で使いますが、 **`E`** や **`O`** を位置から省略し、 *1 つの座標だけを使う*, **`L`**, **`C`** または **`R`**、 `*content*` と、その位置の *偶数ページと奇数ページの両方に配置されます*.

**例**

次の例では、 **`E`** や **`O`** です `*locations*` を省略することを示しています `\fancyhead` と \\`fancyfoot`。また、次のコマンドも使用します。

* `\pagestyle{fancy}` ページスタイルを `fancyhdr`
* `\fancyhead{}\fancyfoot{}` が設定したものにする `\fancyhf{}`)

```latex
\begin{document}
% ページスタイルを「fancy」に設定...
\pagestyle{fancy}
%...  سپس設定する。

% すべてのヘッダーとフッターを消去（\fancyhf{} も参照）
\fancyhead{}\fancyfoot{}

% 中央のヘッダー位置を設定するが、O または E は指定しない
\fancyhead[C]{ヘッダー中央のすべてのページにおける: \thepage}

% 左のフッター位置を設定するが、O または E は指定しない
\fancyfoot[L]{フッター左側のすべてのページにおける: \thepage}

% いくつかの内容:
これは 1 ページ目です。\newpage
これは 2 ページ目です。
```

[この `fancyhdr` Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=fancyhdr+package+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%25...+then+configure+it.%0A%0A%25+Clear+all+headers+and+footers+%28see+also+%5Cfancyhf%7B%7D%29%0A%5Cfancyhead%7B%7D%5Cfancyfoot%7B%7D%0A%0A%25+Set+the+Centre+header+location+but+do+not+specify+O+or+E%0A%5Cfancyhead%5BC%5D%7BIn+the+centre+of+the+header+on+all+pages%3A+%5Cthepage%7D%0A%0A%25+Set+the+Left+footer+location+but+do+not+specify+O+or+E%0A%5Cfancyfoot%5BL%5D%7BOn+the+left+of+the+footer+on+all+pages%3A+%5Cthepage%7D%0A%0A%25+Some+content%3A%0AThis+is+page+1.%5Cnewpage%0AThis+is+page+2.%0A%5Cend%7Bdocument%7D)

次の図は、このコードによって生成された出力に注釈を付けたものです。

![両面 LaTeX 文書で単一の fancyhdr 座標を使う](/files/5f806dde9e8d9f011f45800394a78b370ef1f1c7)

この図からわかるように、次のコードは

```latex
\fancyhead[C]{ヘッダー中央のすべてのページにおける: \thepage}
```

\*\*`C`\*\*cent​re のヘッダー位置を設定しますが、それが \*\*`O`\*\*odd または \*\*`E`\*\*even ページに現れるかどうかは指定しません。 **`O`** や **`E`** 座標を省略すると、\*\*`C`\*\*centre ゾーンのヘッダー内容が奇数ページと偶数ページの両方に表示されます。

さらに、このコード断片は

```latex
\fancyfoot[L]{フッター左側のすべてのページにおける: \thepage}
```

\*\*`L`\*\*eft のフッター位置を設定しますが、奇数ページか偶数ページかは指定しません。 **`O`** や **`E`** 座標を省略すると、\*\*`L`\*\*eft ゾーンの内容が、奇数ページと偶数ページの両方のフッターの左ゾーンに表示されるということです。

**両面文書で単一の座標を使う: L、C、R を省略する**

もし **`L`**, **`C`** や **`R`** を両面文書のある位置で使い、 *1 つの座標だけを使う*, **`E`** または **`O`**、 `*content*` は *3 つのすべてのゾーンに配置されます* その位置で指定された偶数ページまたは奇数ページに。

**例**

次の例では、奇数ページと偶数ページのヘッダーとフッターを設定しますが、いずれの `*locations*` を `\fancyhead` や `\fancyfoot` コマンドも「ゾーン」、 **`L`**, **`C`** または **`R`**&#x3092;指定していません。 `*content*` が 3 つのすべてのゾーンに複製されることに注目してください。 `*content*` が

```latex
\begin{document}
% ページスタイルを「fancy」に設定...
\pagestyle{fancy}
%...  سپس設定する。

% すべてのヘッダーとフッターを消去（\fancyhf{} も参照）
\fancyhead{}\fancyfoot{}

% 偶数ページ用のヘッダーとフッターを設定
% ただしゾーン（L, C, または R）は省略
\fancyhead[E]{Header: even page \thepage}
\fancyfoot[E]{Footer: even page \thepage}

% 奇数ページ用のヘッダーとフッターを設定
% ただしゾーン（L, C, または R）は省略
\fancyhead[O]{Header: odd page \thepage}
\fancyfoot[O]{Footer: odd page \thepage}

% いくつかの内容:
これは 1 ページ目です。\newpage
これは 2 ページ目です。
```

[この `fancyhdr` Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=fancyhdr+package+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%25...+then+configure+it.%0A%0A%25+Clear+all+headers+and+footers+%28see+also+%5Cfancyhf%7B%7D%29%0A%5Cfancyhead%7B%7D%5Cfancyfoot%7B%7D%0A%0A%25+Set+the+header+and+footer+for+Even%0A%25+pages+but+omit+the+zone+%28L%2C+C+or+R%29%0A%5Cfancyhead%5BE%5D%7BHeader%3A+even+page+%5Cthepage%7D%0A%5Cfancyfoot%5BE%5D%7BFooter%3A+even+page+%5Cthepage%7D%0A%0A%25+Set+the+header+and+footer+for+Odd%0A%25+pages+but+omit+the+zone+%28L%2C+C+or+R%29%0A%5Cfancyhead%5BO%5D%7BHeader%3A+odd+page+%5Cthepage%7D%0A%5Cfancyfoot%5BO%5D%7BFooter%3A+odd+page+%5Cthepage%7D%0A%0A%25+Some+content%3A%0AThis+is+page+1.%5Cnewpage%0AThis+is+page+2.%0A%5Cend%7Bdocument%7D)

次の図は、このコードによって生成された出力に注釈を付けたものです。

![](/files/1688e29733de92b9e1e676967c969406061abe82)

次のコードは、 **`E`偶数ページ用のヘッダーとフッターを設定しますが、ゾーン座標（`L`**, **`C`** または **`R`**):

```latex
\fancyhead[E]{Header: even page \thepage}
\fancyfoot[E]{Footer: even page \thepage}
```

その結果は次のとおりです。

* **偶数ページのヘッダー** には `Header: even page \thepage` が 3 つのヘッダーゾーンすべて&#x306B;**`L`**, **`C`** や **`R`**)
* **偶数ページのフッター** には `Footer: even page \thepage` が 3 つのフッターゾーンすべて&#x306B;**`L`**, **`C`** や **`R`**)

次のコードは、 **`O`奇数ページだけでなく、ゾーン座標も省略する（`L`**, **`C`** または **`R`**):

```latex
\fancyhead[O]{Header: odd page \thepage}
\fancyfoot[O]{Footer: odd page \thepage}
```

これは、偶数ページの場合と同様の結果を生み出します：

* **奇数ページのヘッダー** には `ヘッダー: 奇数ページ \thepage` が 3 つのヘッダーゾーンすべて&#x306B;**`L`**, **`C`** や **`R`**)
* **奇数ページのフッター** には `フッター: 奇数ページ \thepage` が 3 つのフッターゾーンすべて&#x306B;**`L`**, **`C`** や **`R`**)

#### \fancyhf: 最大3つの座標を使う

`\fancyhf` は、ヘッダーとフッターの指定を組み合わせるために使える、より一般的なコマンドです。これを行うために、次の座標をサポートしています **`H`** （\*\*`H`\*\*ヘッダー）と **`F`** （\*\*`F`\*\*フッター）。このコマンドの一般形は

* `\fancyhf[*locations*]{*content*}`

ここで `*locations*` は、位置のオプションのコンマ区切りリストで、2つまたは3つの座標によって指定され、配置します `*content*`.

このコマンドはヘッダーの内容を指定できるため *や* フッターには、第3の座標が必要です **`H`** または **`F`** 完全に指定するには `*locations*`。たとえば、左側の（偶数）ページ上のフッターの中央ゾーンを使う（参照する）には、これを次の3つの座標として指定します **`EFC`**:

* \*\*`E`\*\*偶数ページ
* \*\*`F`\*\*footer を示すため
* \*\*`C`\*\*中央ゾーン

座標の順序は重要ではないことに注意してください： **`EFC`** は、次と同じ結果になります **`FEC`** などです。

以下の例では `\fancyhf` を使って、すべてのヘッダーとフッターの\*\*`C`\*\*中央ゾーンに内容を配置しています：

```latex
\begin{document}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[EHC]{Even+Header+Centre}
\fancyhf[EFC]{Even+Footer+Centre}
\fancyhf[OFC]{Odd+Footer+Centre}
\fancyhf[OHC]{Odd+Header+Centre}
\lipsum[1]\newpage\lipsum[1]
```

[この `\fancyhf` Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+the+fancyhf+command\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D10mm%2C%25+Set+%5Cheadheight+to+10mm%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Blipsum%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cpagestyle%7Bfancy%7D%0A%5Cfancyhf%7B%7D%0A%5Cfancyhf%5BEHC%5D%7BEven%2BHeader%2BCentre%7D%0A%5Cfancyhf%5BEFC%5D%7BEven%2BFooter%2BCentre%7D%0A%5Cfancyhf%5BOFC%5D%7BOdd%2BFooter%2BCentre%7D%0A%5Cfancyhf%5BOHC%5D%7BOdd%2BHeader%2BCentre%7D%0A%5Clipsum%5B1%5D%5Cnewpage%5Clipsum%5B1%5D%0A%5Cend%7Bdocument%7D)

次の図は、前の例で生成された出力に注釈を付けたものです：

![fancyhdr の \fancyhf コマンドを使った例](/files/d2cdba178899066856255a33eb9ee093a4bdcb57)

### 例

#### ヘッダーとフッターで基本ルール（線）を使う

次のルール関連コマンドは、次の 4.x 版で提供されています `fancyhdr`:

* **`\headrulewidth`**：ヘッダー下の線の太さを定義するマクロ
* **`\footrulewidth`**：フッター上の線の太さを定義するマクロ
* **`\headruleskip`**：線とヘッダーテキストの間隔を定義するマクロ（バージョン 4.0 以降でのみ利用可能）
* **`\footruleskip`**：線とフッターテキストの間隔を定義するマクロ
* **`\headrule`** ヘッダールール（線）を完全に再定義するマクロ
* **`\footrule`** フッタールール（線）を完全に再定義するマクロ
* **`\headwidth`** ヘッダーとフッターの総幅を定義する長さパラメータ

**注**:

* のデフォルト値は `\headrulewidth` は `0.4pt` で、のデフォルト値は `\footrulewidth` は `0pt` そのため、既定ではそのルールはフッターには表示されません。
* を使う必要があります `\renewcommand` で保持されている幅の値を変更するには `\headrulewidth` または `\footrulewidth`
* 同様に、 `\renewcommand` を使って、ヘッダーまたはフッターのテキスト間の空白を変更します。これは `\headruleskip` または `\footruleskip` でそれぞれ設定されています

例:

```latex
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{4pt}
\renewcommand{\headruleskip}{10mm}
\renewcommand{\footruleskip}{10pt}
```

* **注**：それは *なぜなら* 次のコマンドは *マクロ*
* * `\headrulewidth`
  * `\footrulewidth`
  * `\headruleskip`
  * `\footruleskip`

あなたが *必要があります* 使って `\renewcommand` これらのコマンドによって保持されている値を変更します。次のコード *は動作しません*:

```latex
\setlength{\headrulewidth}{2pt}% は動作しません
\setlength{\headruleskip}{10mm}% も動作しません
```

次の例ではルールの幅を変更し、ルール（線）とヘッダー／フッターのテキストとの距離をどのように変更するかを示します— `\headruleskip` や `\footruleskip`:

```latex
\begin{document}
% ページスタイルを「fancy」に設定...
\pagestyle{fancy}
%...  سپس設定する。
\renewcommand{\headruleskip}{10mm}
\renewcommand{\footruleskip}{10pt}
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{4pt}
% いくつかの内容:
\chapter{Wrangling settings}
\section{Page 1}
これは1ページ目です。
\newpage
\section{Page 2}
これは 2 ページ目です。
\end{document}
```

[この `fancyhdr` Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=fancyhdr+package+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0A%25+Set+%5Cheadheight+to+15mm+to+accommodate%0A%25+value+of+%5Cheadruleskip%0Aheadheight%3D15mm%2C%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%25...+then+configure+it.%0A%5Crenewcommand%7B%5Cheadruleskip%7D%7B10mm%7D%0A%5Crenewcommand%7B%5Cfootruleskip%7D%7B10pt%7D%0A%5Crenewcommand%7B%5Cheadrulewidth%7D%7B2pt%7D%0A%5Crenewcommand%7B%5Cfootrulewidth%7D%7B4pt%7D%0A%25+Some+content%3A%0A%5Cchapter%7BWrangling+settings%7D%0A%5Csection%7BPage+1%7D%0AThis+is+page+1.%0A%5Cnewpage%0A%5Csection%7BPage+2%7D%0AThis+is+page+2.%0A%5Cend%7Bdocument%7D)

#### ヘッダーで装飾的なルールを使う

次の例は、次の中に含まれている例を元にしています `fancyhdr` パッケージのドキュメントで、次を使っています [`fourier-orns` パッケージ](https://ctan.org/pkg/fourier?lang=en).

```latex
\documentclass{book}
\usepackage[paperheight=16cm, paperwidth=12cm,% 用紙の高さと幅を設定
includehead,
nomarginpar,% 余白段落は不要
textwidth=10cm,% \textwidth を 10cm に設定
headheight=14pt,% 装飾ルールに対応するため、\headheight を 14pt に設定
]{geometry}
\usepackage{fourier-orns}
\usepackage{fancyhdr}
\renewcommand{\headrule}{%
\vspace{-8pt}\hrulefill
\raisebox{-2.1pt}{\quad\decofourleft\decotwo\decofourright\quad}\hrulefill}
\title{Decorative line}
\author{Overleaf}
\date{2022年8月}
\begin{document}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE]{\nouppercase{\rightmark\hfill\leftmark}}
\fancyhead[RO]{\nouppercase{\leftmark\hfill\rightmark}}
\fancyfoot[LE,RO]{\hfill\thepage\hfill}
\chapter{Fancy rules!}
\section{導入}
この例は \texttt{fancyhdr} のドキュメントから取られています。
\newpage
\section{See the header}
\newpage
\section{Yes, very neat!}
\end{document}
```

[Overleaf でこの例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Drawing+fancy+rules+in+headers\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D14pt%2C%25+Set+%5Cheadheight+to+14pt+to+accommodate+our+fancy+rule%21%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfourier-orns%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Crenewcommand%7B%5Cheadrule%7D%7B%25%0A%5Cvspace%7B-8pt%7D%5Chrulefill%0A%5Craisebox%7B-2.1pt%7D%7B%5Cquad%5Cdecofourleft%5Cdecotwo%5Cdecofourright%5Cquad%7D%5Chrulefill%7D%0A%5Ctitle%7BDecorative+line%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BAugust+2022%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cpagestyle%7Bfancy%7D%0A%5Cfancyhf%7B%7D%0A%5Cfancyhead%5BLE%5D%7B%5Cnouppercase%7B%5Crightmark%5Chfill%5Cleftmark%7D%7D%0A%5Cfancyhead%5BRO%5D%7B%5Cnouppercase%7B%5Cleftmark%5Chfill%5Crightmark%7D%7D%0A%5Cfancyfoot%5BLE%2CRO%5D%7B%5Chfill%5Cthepage%5Chfill%7D%0A%5Cchapter%7BFancy+rules%21%7D%0A%5Csection%7BIntroduction%7D%0AThis+example+is+taken+from+the+%5Ctexttt%7Bfancyhdr%7D+documentation.%0A%5Cnewpage%0A%5Csection%7BSee+the+header%7D%0A%5Cnewpage%0A%5Csection%7BYes%2C+very+neat%21%7D%0A%5Cend%7Bdocument%7D)

この例では次の出力が生成されます:

![fourier-orns パッケージを介してヘッダーに装飾的なルールを作成する例](/files/3a8b7e1e539f692bb73965c2e87c8892b13187f0)

* この例のコマンドに関する注記
  * **`\headrule`**：ヘッダー内の装飾線をどのように描くかを定義するマクロです。ここでは、次の装飾を含む線を描くよう再定義されています [`fourier-orns` パッケージ](https://ctan.org/pkg/fourier?lang=en).
  * **`\leftmark`** や **`\rightmark`**：これらのコマンドは、LaTeX のセクショニングコマンドによって挿入される「マークデータ」を取得するために使われます。これらのコマンドのより完全な説明については、併載記事 [*LaTeX はどのようにヘッダーとフッターを組版するのですか？*](/latex/ja/xiang-xi-ji-shi/23-how-does-latex-typeset-headers-and-footers.md)
  * **`\nouppercase`**：次のパッケージによって提供されるコマンド `fancyhdr` を使うと、ヘッダーまたはフッターのテキストが大文字で組まれるのを防げます。これは LaTeX のヘッダーとフッターの既定のスタイルです

#### fancyhdr 警告: \headheight が小さすぎます

次の `fancyhdr` 警告を受け取った場合、 `\headheight` が小さすぎるので、 *パッケージを使う必要はありません。* ある値にリセットしてください `高さ` と書くことで

```latex
\setlength{\headheight}{height}
```

しかし [推奨される解決策は、 `geometry` パッケージ](https://tex.stackexchange.com/a/100408) を使い、その `headheight=*height*` オプションを適用して `\headheight` から `*height*`.

の値を設定することです `\headheight` 次の例では、以前の book クラスの例に戻り、 `を \headheight=2cm で 2cm に設定し直します`:

```latex
\documentclass{book}
\usepackage[paperheight=16cm, paperwidth=12cm,% 用紙の高さと幅を設定
includehead,% 以下に説明があります
nomarginpar,% 余白段落は不要
textwidth=10cm,% \textwidth を 10cm に設定
headheight=2cm,% \headheight を 2cm に設定
showframe % ページレイアウトを表示
]{geometry}
\title{\TeX{} ユーザーの回想録}
\author{Overleaf}
\begin{document}

\frontmatter
\maketitle
これはローマ数字を使う frontmatter です。

\mainmatter
\chapter{どこから始めるか}
第1章: 1ページ目で終わる短い章。

\chapter{私が覚えていること}
第2章: 3ページ目から始まるので、\LaTeX{} は「空白」の2ページ目を挿入します。
\end{document}
```

[Overleaf で開く: 設定する例 `\headheight` geometry パッケージを使って](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Setting+headheight+using+the+geometry+package\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%25+See+below+for+an+explanation%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D2cm%2C%25+Set+%5Cheadheight+to+2cm%0Ashowframe+%25+Show+the+page+layout%0A%5D%7Bgeometry%7D%0A%5Ctitle%7BMemoirs+of+a+%5CTeX%7B%7D+user%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cfrontmatter%0A%5Cmaketitle%0AThis+is+frontmatter+which+uses+Roman+numerals.%0A%0A%5Cmainmatter%0A%5Cchapter%7BWhere+do+I+start%7D%0AChapter+1%3A+A+short+chapter+that+ends+on+page+1.%0A%0A%5Cchapter%7BThings+I+remember%7D%0AChapter+2%3A+Starts+on+page+3%2C+so+%5CLaTeX%7B%7D+inserts+a+%60%60blank%27%27+page+2.%0A%5Cend%7Bdocument%7D)

**geometry パッケージに関する注記**

上の例では、次のいくつかのオプションを使っています `geometry` パッケージを使ったサンプルコードです：

* `nomarginpar`：余白段落は不要であることを指定します
* `textwidth=10cm`：次の値（10cm）を設定します `\textwidth`、LaTeX の [ページレイアウトパラメータの1つです](/latex/ja/xiang-xi-ji-shi/04-a-visual-guide-to-latex-s-page-layout-parameters.md)
* `を \headheight=2cm で 2cm に設定し直します`：次の値（2mm）を設定します `\headheight`、LaTeX の [ページレイアウトパラメータの1つです](/latex/ja/xiang-xi-ji-shi/04-a-visual-guide-to-latex-s-page-layout-parameters.md)
* `showframe`：ページレイアウトを描画します

この `geometry` パッケージはまた、LaTeX のページレイアウトパラメータの特定の値の計算方法に影響するオプションも提供します。たとえば：

* `includehead`
* `includefoot`

私たちの例（上）は `includehead` を使い、テキスト領域の高さが `headheight`の値を変えることで直接影響を受けるようにしています。次の図は、 `geometry` パッケージのドキュメントからコピーしたもので、 `includehead` や `includefoot` オプションが文書のテキスト高さの計算にどのように影響するかを示しています：

![geometry パッケージのドキュメントからの画像。includehead および includefoot オプションが文書のテキスト高さの計算にどう影響するかを示す](/files/04587e75e51bb8834bb86ba1643e43274f494c5a)

次の点に注意してください。 `geometry` パッケージは、次のオプションを通じてテキスト領域の高さを参照します `textheight` 一方、LaTeX は同様の名前の [`\textheight` ページレイアウトパラメータを使います](/latex/ja/xiang-xi-ji-shi/04-a-visual-guide-to-latex-s-page-layout-parameters.md#notes-on-the-page-layout-parameters-and-equations).

#### ページ X / N を含むフッター

出典: tex.stackexchange に投稿されたコードの編集版： <https://tex.stackexchange.com/a/282840>.

この例では、現在のページ番号と総ページ数を表示するフッターを作成します。これは、 [`lastpage` パッケージ](https://ctan.org/pkg/lastpage?lang=en) を使い、修正版の `plain` ページスタイルを次の方法で実装したものと組み合わせています `\fancypagestyle` によって提供されるコマンド `fancyhdr`.

```latex
\documentclass[12pt]{article}
\usepackage[paperheight=16cm, paperwidth=12cm,% 用紙の高さと幅を設定
includehead,% 以下に説明があります
nomarginpar,% 余白段落は不要
textwidth=10cm,% \textwidth を 10cm に設定
headheight=16pt % fancyhr 警告を避けるため、\headheight を 16pt に設定
]{geometry}
\usepackage{lastpage}
\usepackage{fancyhdr}
\usepackage{lipsum} % ダミーテキスト用
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[C]{\thepage\ of \pageref{LastPage}}
\fancypagestyle{plain}{%
  \renewcommand{\headrulewidth}{0pt}%
  \fancyhf{}%
  \fancyfoot[C]{\thepage\ of \pageref{LastPage}}}
\begin{document}
\title{Another fancyhdr demo}
\author{\texttt{tex.stackexchange} \textit{ほか}}
\maketitle

\lipsum
\end{document}
```

[Overleaf でこの例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Footers+with+page+X+of+Y\&snip=%5Cdocumentclass%5B12pt%5D%7Barticle%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%25+See+below+for+an+explanation%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D16pt+%25+Set+%5Cheadheight+to+16pt+to+avoid+fancyhr+warnings%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Blastpage%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cusepackage%7Blipsum%7D+%25+just+for+mock+text%0A%5Cpagestyle%7Bfancy%7D%0A%5Crenewcommand%7B%5Cheadrulewidth%7D%7B0pt%7D%0A%5Cfancyfoot%5BC%5D%7B%5Cthepage%5C+of+%5Cpageref%7BLastPage%7D%7D%0A%5Cfancypagestyle%7Bplain%7D%7B%25%0A++%5Crenewcommand%7B%5Cheadrulewidth%7D%7B0pt%7D%25%0A++%5Cfancyhf%7B%7D%25%0A++%5Cfancyfoot%5BC%5D%7B%5Cthepage%5C+of+%5Cpageref%7BLastPage%7D%7D%7D%0A%5Cbegin%7Bdocument%7D%0A%5Ctitle%7BAnother+fancyhdr+demo%7D%0A%5Cauthor%7B%5Ctexttt%7Btex.stackexchange%7D+%5Ctextit%7Bet+al%7D%7D%0A%5Cmaketitle%0A%0A%5Clipsum%0A%5Cend%7Bdocument%7D)

#### 完全に空白のページを作成する: ヘッダーもフッターもなし

次に記されているように [`fancyhdr` パッケージのドキュメント](http://mirrors.ctan.org/macros/latex/contrib/fancyhdr/fancyhdr.pdf)、文書を使って作成する場合

* その `book` クラス *〜なしの* その `openany` オプション、または
* その `レポート` クラスを `openright` オプションからプレミアムアカウントで利用可能です

任意の部分（`\part{...}`）と章（`\chapter{...}`）のページは、奇数（右側）ページで始まります。

ときには、LaTeX は、次の章または節のページが右側ページで始まるようにするため、「空白」のページを挿入する必要がありますが、その「空白」ページにもヘッダーが入り、多くの人には見苦しいものになります。

**book クラス文書における「空白」ページの例**

以下の `book` クラスの例では、右側を向いた章ページ2つを含む5ページが作成されます。

```latex
\begin{document}

\frontmatter
\maketitle
これはローマ数字を使う frontmatter です。

\mainmatter
\chapter{どこから始めるか}
第1章: 1ページ目で終わる短い章。

\chapter{私が覚えていること}
第2章: 3ページ目から始まるので、\LaTeX{} は「空白」の2ページ目を挿入します。

\end{document}
```

[この `book` の例（Overleaf）](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Demonstrating+blank+pages\&snip=%5Cdocumentclass%7Bbook%7D%0A%25+Choose+a+conveniently+small+page+size%0A%5Cusepackage%5Bpaperheight%3D16cm%2Cpaperwidth%3D12cm%2Ctextwidth%3D10cm%5D%7Bgeometry%7D%0A%5Ctitle%7BMemoirs+of+a+%5CTeX%7B%7D+user%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cfrontmatter%0A%5Cmaketitle%0AThis+is+frontmatter+which+uses+Roman+numerals.%0A%0A%5Cmainmatter%0A%5Cchapter%7BWhere+do+I+start%7D%0AChapter+1%3A+A+short+chapter+that+ends+on+page+1.%0A%0A%5Cchapter%7BThings+I+remember%7D%0AChapter+2%3A+Starts+on+page+3%2C+so+%5CLaTeX%7B%7D+inserts+a+%60%60blank%27%27+page+2.%0A%0A%5Cend%7Bdocument%7D)

次の注釈付き図が示すように、LaTeX が2ページ目を挿入したため第2章は3ページ目から始まります。その2ページ目は名目上は「空白」ですが、見苦しいヘッダーが含まれています。

![book クラス文書における空白ページの例](/files/8214036ab7ce97cb5c9dd82e616d8d92e1f17aed)

挿入されたページ（上の2ページ目のようなもの）を完全に空白にするために、さまざまな仕組み—コードやパッケージ—を使うことができます。いくつか例を挙げます：

* 次を使います `emptypage` 文書のプリアンブルに次の行を追加して、パッケージを使います：

```latex
\usepackage{emptypage}
```

* 第1章の最後に手動で空白ページを挿入し、第2章が自然に右側ページで始まるようにして、LaTeX に新しいページを強制させる必要をなくします。次のコードが、 `fancyhdr` パッケージのドキュメントで提案されています：

```latex
\clearpage
\begingroup
\pagestyle{empty}\cleardoublepage
\endgroup
```

* 同様に、第1章の最後に新しいページを作成し、 `\thispagestyle{empty}`:

```latex
\newpage\thispagestyle{empty}
```

を使ってそのスタイルを empty に設定できます。真に空白のページの使用に関する詳細や例については、 [TUG FAQ](https://texfaq.org/FAQ-reallyblank) を参照するか、 [タグ付きの質問 `blank-page` を TeX.stackechange で検索してください](https://tex.stackexchange.com/questions/tagged/blank-page).

* **ヒント**：TeX FAQ には次の題名の項目があります [ページ番号を消すための](https://texfaq.org/FAQ-nopageno%7CHow) いくつか役立つ助言が含まれています。

#### 単一ページのスタイルを変更する

特定のページのスタイルを変更すると便利な場合があります。たとえば、現在の章ページからヘッダーとフッターを हटします：

```latex
\begin{document}
\maketitle
\chapter{Using different page styles}
\lipsum[1] % \usepackage{lipsum} 経由
\chapter{Sample Chapter}
\thispagestyle{empty} % 章ページからヘッダー/フッターを削除
\lipsum[1]
\clearpage
\section{New section}
\lipsum[1]
\end{document}
```

[Overleaf でこの例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Setting+the+style+of+a+single+page\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%7Blipsum%7D%0A%5Ctitle%7BChanging+the+style+of+a+single+page%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%5Cchapter%7BUsing+different+page+styles%7D%0A%5Clipsum%5B1%5D+%25+via+%5Cusepackage%7Blipsum%7D%0A%5Cchapter%7BSample+Chapter%7D%0A%5Cthispagestyle%7Bempty%7D+%25+remove+headers%2Ffooters+from+the+chapter+page%0A%5Clipsum%5B1%5D%0A%5Cclearpage%0A%5Csection%7BNew+section%7D%0A%5Clipsum%5B1%5D%0A%5Cend%7Bdocument%7D)

#### 複数行のヘッダーまたはフッター

によって生成されるヘッダーとフッターは `fancyhdr` 複数行にできます。次の例は `fancyhdr` のドキュメントを基にしていますが、複数行ヘッダーを含むよう拡張されています。この例では `datetime2` パッケージコマンド `\DTMnow` を使って、下書き文書が組版された日付を挿入します。コマンド `\\` はヘッダーの1行目を終えるために使われます。

```latex
\documentclass{book}
\usepackage[paperheight=16cm, paperwidth=12cm,% 用紙の高さと幅を設定
includehead,
nomarginpar,% 余白段落は不要
textwidth=10cm,% \textwidth を 10cm に設定
headheight=25pt,% 複数行ヘッダーに対応するため、\headheight を 25pt に設定
]{geometry}
\usepackage{fancyhdr}
\usepackage{datetime2}
\begin{document}
% ページスタイルを「fancy」に設定...
\pagestyle{fancy}
%...  سپس設定する。
\fancyhead{} % すべてのヘッダーフィールドをクリア
\fancyhead[RO,LE]{\textbf{DRAFT} (Typeset \DTMnow)\\\textbf{The performance of new graduates}}
\fancyfoot{} % すべてのフッターフィールドをクリア
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[LO,CE]{差出人: K. Grant}
\fancyfoot[CO,RE]{宛先: Dean A. Smith}
% いくつかの内容:
これは 1 ページ目です。\newpage
これは 2 ページ目です。
\end{document}
```

[この `fancyhdr` Overleaf 上の例を開く](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Multiline+header+fancyhdr+package+example\&snip=%5Cdocumentclass%7Bbook%7D%0A%5Cusepackage%5Bpaperheight%3D16cm%2C+paperwidth%3D12cm%2C%25+Set+the+height+and+width+of+the+paper%0Aincludehead%2C%0Anomarginpar%2C%25+We+don%27t+want+any+margin+paragraphs%0Atextwidth%3D10cm%2C%25+Set+%5Ctextwidth+to+10cm%0Aheadheight%3D25pt%2C%25+Set+%5Cheadheight+to+25pt+to+accommodate+the+multiline+header%0A%5D%7Bgeometry%7D%0A%5Cusepackage%7Bfancyhdr%7D%0A%5Cusepackage%7Bdatetime2%7D%0A%5Cbegin%7Bdocument%7D%0A%25+Set+the+page+style+to+%22fancy%22...%0A%5Cpagestyle%7Bfancy%7D%0A%25...+then+configure+it.%0A%5Cfancyhead%7B%7D+%25+clear+all+header+fields%0A%5Cfancyhead%5BRO%2CLE%5D%7B%5Ctextbf%7BDRAFT%7D+%28Typeset+%5CDTMnow%29%5C%5C%5Ctextbf%7BThe+performance+of+new+graduates%7D%7D%0A%5Cfancyfoot%7B%7D+%25+clear+all+footer+fields%0A%5Cfancyfoot%5BLE%2CRO%5D%7B%5Cthepage%7D%0A%5Cfancyfoot%5BLO%2CCE%5D%7BFrom%3A+K.+Grant%7D%0A%5Cfancyfoot%5BCO%2CRE%5D%7BTo%3A+Dean+A.+Smith%7D%0A%25+Some+content%3A%0AThis+is+page+1.%5Cnewpage%0AThis+is+page+2.%0A%5Cend%7Bdocument%7D)

次の図は、この例で生成される出力を示しています。

![fancyhdr によって生成された複数行ヘッダーの例](/files/97202ebd249271f99aea25aa06d436d822f022a9)


---

# 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/02-headers-and-footers.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.
