The fancyhdr package manual can be obtained from texdoc fancydhr in CMD.
To use custom headers and footers in latex, you generally need to use the fancy macro package. The key is to think about the following examples, and after looking at the corresponding instructions, you can generally get the results you want. The following content mainly comes from CTEX - Online documentation, the example part has been modified and can be compiled directly. When using LaTeX to typeset articles and books, four header and footer formats are defined by default:
empty | No header and footer |
plain | There is no header, and the page number is placed in the middle of the footer. |
headings | There is no footer, the header contains the title and page number of the chapter. |
myheadings | There are no footers, header page numbers and user-defined information. |
Using the commands provided by the fancyhdr package, you can easily do:
- Customize headers and footers.
- Add decorative horizontal lines to headers and footers.
- The width of the header and footer can exceed the width of the body text.
- Multi-line headers and footers.
- Parity pages use different formats for headers and footers.
- The first page of each chapter uses a different format for headers and footers.
- Floating object pages use headers and footers in different formats.
- Control the font of headers and footers, including glyph, font family, capitalization, etc.
Simple example:
\documentclass{article} \usepackage{fancyhdr} \pagestyle{fancy} \lhead{} \chead{} \rhead{\bfseries The performance of new graduates} \lfoot{From: K. Grant} \cfoot{To: Dean A. Smith} \rfoot{\thepage} \renewcommand{\headrulewidth}{0.4pt} \renewcommand{\footrulewidth}{0.4pt} %...... \begin{document} ...... test! \end{document}
In the above example, \thepage gives the page number of the current page, while \bfseries causes LaTeX to typeset the header in bold. If you want to use other forms in the document, such as no header and footer on the first page, you can use the command after \begin{document} and \maketitle
\thispagestyle{empty}
By default, the \maketitle command automatically formats its page as plain. Therefore, if you want to use fancy format on this page, you should use the command \thispagestyle{fancy} after \maketile.
Here's an example in a two-sided page layout:
\documentclass{book} \usepackage{fancyhdr} \fancyhead{} % clear all fields \fancyhead[RO,LE]{\bfseries The performance of new graduates} \fancyfoot[LE,RO]{\thepage} \fancyfoot[LO,CE]{From: K. Grant} \fancyfoot[CO,RE]{To: Dean A. Smith} \renewcommand{\headrulewidth}{0.4pt} \renewcommand{\footrulewidth}{0.4pt} \begin{document} ...... test! \end{document}
The meanings of the letters in square brackets here are:
E | even pages |
O | odd-numbered pages |
L | the left part of the header or footer |
C | The middle part of the header or footer |
R | The right part of the header or footer |
H | header |
F | footer |
\documentclass{book} \usepackage{CJK} \usepackage{fancyhdr} %...... \begin{document} \begin{CJK}{GBK}{song} \pagestyle{fancy} \fancyhead{} % clear all fields \fancyhead[RO,LE]{\CJKfamily{hei} \bfseries \LaTeX{} 排版系统} \fancyhead[LO,RE]{\CJKfamily{hei>} \bfseries \leftmark} \fancyfoot[LE,RO]{ \thepage } \fancyfoot [LO,RE]{ \CJKfamily {kai} July 2000 AD} \renewcommand { \headrulewidth } { 0.4pt } \renewcommand { \footrulewidth } { 0.4pt } % ...... test! \end{CJK} \end{document}