我使用 fancyhdr 设置页眉和页脚。但是,这些只显示在章节页面上。非章节页面的页脚和页眉都是空白的。为什么会这样?
这是 MWE
% packages and general setup
\documentclass[12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[a4paper, width = 150mm, top = 25mm, bottom = 40mm, bindingoffset = 6mm]{geometry}
\AtBeginDocument{\renewcommand{\bibname}{References}}
% package and setup for header and footer
\setlength{\headsep}{25pt}
\setlength{\footskip}{20mm}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\fancyhf{}
\setlength{\headheight}{14.49998pt}
\fancypagestyle{plain}{% the preset of fancyhdr
\fancyhf{} % clear all header and footer fields
\fancyhead{}
\fancyhead[RO, LE]{\ifnum\value{chapter}>0 \thechapter \hspace{1pt} \leftmark \fi}
\fancyfoot{}
\fancyfoot[LE, RO]{\thepage}
\fancyfoot[LO, RE]{Auther Name}
}
\begin{document}
\chapter{Introduction}
\input{Chapter1}
\end{document}
答案1
普通样式会自动应用于章节的第一页。页码和其他信息通常设置在页面的页脚中,以保持章节页眉的布局。
\fancypagestyle{plain}{% first page of chapters
\fancyhf{} % clear all header and footer fields
\fancyfoot[LE, RO]{\thepage}
\fancyfoot[LO, RE]{Auther Name}
\renewcommand{\headrulewidth}{0pt} % no rule
}
对于其余页面,您需要定义一个单独的样式(在此示例中称为 fancy),并使用\pagestyle{fancy}
\fancypagestyle{fancy}{% all pages
\fancyhf{} % clear all header and footer fields
\fancyhead[RO, LE]{\leftmark}
\fancyfoot[LE, RO]{\thepage}
\fancyfoot[LO, RE]{Auther Name}
}
\documentclass[12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[a4paper, width = 150mm, top = 25mm, bottom = 40mm, bindingoffset = 6mm]{geometry}
\AtBeginDocument{\renewcommand{\bibname}{References}}
% package and setup for header and footer
\setlength{\headsep}{25pt}
\setlength{\footskip}{20mm}
\setlength{\headheight}{15pt}
\usepackage{fancyhdr}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancypagestyle{plain}{% first page of chapters
\fancyhf{} % clear all header and footer fields
\fancyfoot[LE, RO]{\thepage}
\fancyfoot[LO, RE]{Auther Name}
\renewcommand{\headrulewidth}{0pt} % no rule
}
\fancypagestyle{fancy}{% all pages
\fancyhf{} % clear all header and footer fields
\fancyhead[RO, LE]{\leftmark}
\fancyfoot[LE, RO]{\thepage}
\fancyfoot[LO, RE]{Auther Name}
}
\pagestyle{fancy} % apply the stye <<<<<<<<<<<<<
\usepackage{kantlipsum} % ONLY for dummy text <<<<
\begin{document}
\chapter{Introduction}
\kant[1-6]
\chapter{First}
\kant[1-6]
\end{document}