This page covers the running heads (headers) and feet (footers) at the top and bottom of the page, and how to number pages. We start with LaTeX’s four built-in page styles (empty, plain, headings, myheadings), then look at **fancyhdr**, the standard package for fine-grained control, and finish with \pagenumbering, which sets the page-number format and resets the counter.
The built-in page styles
The basic look of headers and footers is set by the page style. Writing \pagestyle{...} in the preamble is a declaration that applies to every page from that point onward. To give a single page a different style, use \thispagestyle{...} in the body. Four styles are provided as standard:
| Style | What it does |
|---|---|
empty | Header and footer are both empty; no page number |
plain | Empty header; page number centered in the footer. The default for article / report |
headings | Empty footer; the header carries section/chapter titles and the page number (a running head). The default for book |
myheadings | Like headings, but you supply the running-head text yourself via \markboth / \markright |
The default style depends on the class: article and report use plain (page number bottom-center), while book uses headings (running heads). A useful exception to remember: pages carrying \maketitle, \part, or \chapter automatically get \thispagestyle{plain}. So even with \pagestyle{empty}, a chapter-opening page still shows a centered page number at the bottom — to remove that too, write \thispagestyle{empty} right after the \chapter.
The content of the headings running head is also class-dependent. In book / report (two-sided), left pages show the chapter title and right pages show the section title; in article (one-sided) each page shows the section title and page number. Choosing myheadings lets you supply those strings yourself with \markboth{left-page}{right-page} (for two-sided) or \markright{right-page}.
These built-in styles are convenient, but they cannot produce free layouts such as “document title on the left, page number on the right.” For that, reach for fancyhdr, covered next.
The fancyhdr package
fancyhdr is the standard package for building headers and footers freely (written by Piet van Oostrum). Load it and declare \pagestyle{fancy}, and you get three positions — left (L), center (C), right (R) — in each of the header and footer, six slots in all.
The idiom is to first clear all six slots with \fancyhf{}, then set only the ones you need. Use \fancyhead[L]{...} / [C] / [R] for the header and \fancyfoot[L]{...} / [C] / [R] for the footer. If you do not clear first, class-supplied default running heads may linger.
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % 6 つのスロットを全消去
\fancyhead[L]{文書のタイトル} % ヘッダー左
\fancyhead[R]{\thepage} % ヘッダー右にページ番号
\fancyfoot[C]{\today} % フッター中央に日付In two-sided (twoside) documents, combine positions with even (E) and odd (O) pages so spreads line up. [LE,RO] means “left on even pages, right on odd pages” — the classic way to put the page number on the outer (fore-edge) side. A specifier without E/O, like [L], places the same content on both pages even in twoside.
The thickness of the rules drawn below the header and above the footer is controlled by \headrulewidth and \footrulewidth. The defaults are **0.4pt for the header rule and 0pt (no rule)** for the footer rule. Change them with \renewcommand; setting 0pt removes a rule.
\renewcommand{\headrulewidth}{0.4pt} % ヘッダー罫線(既定)
\renewcommand{\footrulewidth}{0pt} % フッター罫線を消す(既定)Chapter/section titles in the running head (\leftmark / \rightmark)
To flow the current chapter/section title into the running head, use \leftmark and \rightmark. In the book / report classes, \leftmark holds the current chapter title and \rightmark holds the current section title. They update automatically whenever a chapter or section command is processed, so each page can show “the chapter/section you are currently in.”
Note that the standard classes uppercase this content. To keep the original capitalization, wrap it in \nouppercase, which fancyhdr provides. Be aware, though, that \nouppercase cancels all uppercasing inside it, which can affect things like uppercase roman numerals in the head.
% 左に章名(大文字化を解除)、右にページ番号
\fancyhead[L]{\nouppercase{\leftmark}}
\fancyhead[R]{\thepage}The “headheight is too small” warning
When using fancyhdr you may see Package fancyhdr Warning: \headheight is too small. This means the height of the box that holds the header, \headheight, is too small for what you have put in it (a rule, a multi-line head, and so on). It can make the header crowd or intrude into the body text.
There are two equally valid fixes. Either enlarge it directly with \setlength{\headheight}{...}, or set it via the geometry package’s headheight= option. The latter keeps the value consistent with the rest of the page-layout calculation, so if you already use geometry, set it there.
% どちらか一方でよい
\setlength{\headheight}{15pt} % 直接広げる
% または geometry 側で
\usepackage[headheight=15pt]{geometry}Page-number format (\pagenumbering)
The format of page numbers is switched with \pagenumbering{...}. The main arguments it accepts are below. The default is Arabic numerals (arabic), starting at 1.
| Argument | Output |
|---|---|
arabic | Arabic numerals: 1, 2, 3 … (the default) |
roman | Lowercase roman numerals: i, ii, iii … |
Roman | Uppercase roman numerals: I, II, III … |
alph | Lowercase letters: a, b, c … (up to 26) |
Alph | Uppercase letters: A, B, C … (up to 26) |
Crucially, \pagenumbering also resets the page counter to 1 when it changes the format. A common book pattern exploits this: number the front matter in lowercase roman starting at i, then switch to \pagenumbering{arabic} at the start of the main text to restart counting at 1. The current page number itself is available as \thepage, and to force a specific number, set the counter directly with \setcounter{page}{...}.
\frontmatter % book クラスなら前付け(これも roman に切替)
\pagenumbering{roman} % i, ii, iii … (カウンタも 1 に戻る)
% 目次・序文など
\mainmatter % 本文
\pagenumbering{arabic} % 1, 2, 3 … (再び 1 から)A worked example
Here is a common two-sided layout built with fancyhdr: the page number on the outer edge, the chapter/section title on the inner edge, and a thin rule under the header. The header height is enlarged a little to avoid the \headheight warning.
\documentclass[twoside]{book}
\usepackage[headheight=15pt]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % まず全消去
\fancyhead[LE,RO]{\thepage} % 外側にページ番号
\fancyhead[RE]{\nouppercase{\leftmark}} % 偶数ページ右=章名
\fancyhead[LO]{\nouppercase{\rightmark}} % 奇数ページ左=節名
\renewcommand{\headrulewidth}{0.4pt} % ヘッダー罫線
\renewcommand{\footrulewidth}{0pt} % フッター罫線なし
\begin{document}
\chapter{はじめに}
\section{背景}
本文がここに入ります。柱に章・節名とページ番号が出ます。
\end{document}In this example the chapter-opening page (the one with \chapter) automatically becomes plain, as noted earlier, so only that page shows no running head and a centered page number at the bottom. To make even that page match the fancy look, redefine the plain style itself with fancyhdr’s \fancypagestyle{plain}{...}.