Page Number, Header, and Footer #
Author: Erhua
Keywords: page number, header, footer
In this section, we discuss page numbers, headers, and footers.
Page Number #
From what we have learned earlier, we know that numbering is controlled by counters. For page numbers, the controller is page
. The command \pagenumbering{format}
is used to control the numbering style of page numbers. It is important to start a new page when using this command, as it will restart the counting on a new page.
% Due to personal preference for the "QingKeBenYueSong" font and liking "JinSe" as an example,
% they are used here, but this is the most complicated way. The following method should be used instead:
% \usepackage{lipsum}
% \lipsum[1-n]
% The simplest and most effective way to use lipsum.
\documentclass[]{article}
\usepackage{ctex}
\setCJKfamilyfont{qingsong}{FZQKBYSJW--GB1-0}
\usepackage[paperwidth = 52mm, paperheight = 72mm]{geometry}
\begin{document}
\CJKfamily{qingsong}
\pagenumbering{roman}% Use Roman numerals as page numbers
(Text)
\newpage
\pagenumbering{arabic}% Use Arabic numerals as page numbers
(Text)
\end{document}
Name | Type |
---|---|
arabic | Arabic number |
roman | Roman numeral |
Roman | Roman numeral |
alph | Lowercase letter |
Alph | Uppercase letter |
Header and Footer #
Predefined Styles #
LaTeX provides several predefined styles for headers and footers, which can be selected from 4 different page styles:
Page Style | Explanation |
---|---|
empty | No header or footer |
plain | No header, centered page number as footer |
headings | No footer, chapter/section name and page number as header |
myheadings | No footer, page number as header |
Command | Explanation |
---|---|
\pagestyle{page style} | Set the page style |
\thispagestyle{page style} | Set the page style for current page |
Name | Description |
---|---|
\leftmark | Applied in header/footer settings, leftMark refers to high-level (chapter and section, where chapter is high-level) |
\rightmark | Applied in header/footer settings, rightMark refers to low-level (section and subsection, where subsection is low-level) |
fancyhdr Package #
This image is taken from the documentation of the fancyhdr package.
The fancy page style provided by the fancyhdr
package divides headers and footers into six parts and two lines.
For single-page documents (one-sided documents, typically article
class):
#
\documentclass[]{ctexart}
\usepackage{fancyhdr} % Use the fancyhdr package
\usepackage[paperwidth = 200mm,paperheight = 150mm]{geometry}
\pagestyle{fancy} % Use the fancy page style
\lhead{Left Header} % Set the left header
\chead{Center Header} % Set the center header
\rhead{\leftmark} % Set the right header to `leftmark`
\lfoot{\rightmark} % Set the left footer to `rightmark`
\cfoot{\thepage} % Set the center footer to the page number
\rfoot{Right Footer} % Set the right footer to "Right Footer"
\usepackage{lipsum}
\begin{document}
\section{JinSeWuDuanWuShiXian}
\subsection{YiXianYiZhuSiHuaNian}
\lipsum[3-5]
\newpage
\section{ZhuangShengXiaoMengMiHuDie}
\subsection{WangDiChunShenTuoDuJuan}
\lipsum[3-5]
\end{document}
For double-sided documents: #
You can use the following method:
\fancyhead[position]{content} % Set the header, where position can be E, O, and L, C, R in combination
\fancyfoot[position]{content} % Set the footer, where position can be E, O, and L, C, R in combination
\fancyhf[position]{content} % Set the header and footer, where position can be H, F, and E, O, and L, C, R in combination
% The line in the header and footer can also be customized. Note that the line width is not a length variable, but a text macro. Modify the definition as follows:
\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.6pt}
\documentclass[]{book}
\usepackage[heading = true]{ctex}
\newCJKfontfamily\qingsong{FZQKBYSJW--GB1-0}
\ctexset{section={name={第,节},titleformat = {\qingsong}}}
\usepackage{fancyhdr}
\usepackage{anyfontsize}
\usepackage[paperwidth = 200mm,paperheight = 150mm]{geometry}
\pagestyle{fancy}
\fancyhf{} % Used to clear all headers and footers
\fancyhead[CO]{\leftmark} % High-level
\fancyhead[CE]{\rightmark} % Low-level
\fancyfoot[CO]{\thepage}
\fancyhf[FR]{$\spadesuit$}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{2pt}
\usepackage{lipsum}
\begin{document}
\chapter{JinSe1}
\section{JinSeWuDuanWuShiXian}
\subsection{YiXianYiZhuSiHuaNian}
\lipsum[3-5]
\newpage
\chapter{JinSe2}
\section{ZhuangShengXiaoMengMiHuDie}
\subsection{WangDiChunShenTuoDuJuan}
\lipsum[3-5]
\end{document}