LaTeX 页眉和页脚

🏷️ bte365 📅 2025-08-07 03:13:35 ✍️ admin 👀 1778 ❤️ 138
LaTeX 页眉和页脚

原 文:Headers and footers 译 者:Xovee 翻译时间:2021年8月12日

LaTeX 页眉和页脚

LaTeX 内置了一批页眉和页脚的样式。你也可以自定义页眉和页脚的样式。

文章目录

LaTeX 页眉和页脚介绍标准的页面样式设置当前页的页面样式自定义单边文档的页面样式自定义双边文档的页面样式页眉和页脚的装饰线参考指南

介绍

页面中页眉和页脚中显示的内容取决于当前页所激活的样式。这些样式的复杂性在书籍中尤为突出:

\documentclass[a4paper,12pt,twoside]{book}

\usepackage[english]{babel}

\usepackage[utf8]{inputenc}

\pagestyle{headings}

\begin{document}

\chapter{Sample Chapter}

\section{New section}

Hello, here is some text without a meaning. This text should

show what a printed text will look like at this place. If you

read this text, you will get no information. Really? Is there

no information? Is there a difference between this text and some

nonsense like ``Huardest gefburn? Kjift " not at all!...

\end{document}

命令\pagestyle{headings}将当前文档的页面样式设置为headings。你可以在下一章中看到更多页面样式的种类。

标准的页面样式

标准的页面样式由下面的命令所激活:

\pagestyle{''style''}

\pagestyle{myheadings}

在这个例子中,myheadings页面样式将页码显示在页面顶端的外角落。

此外,还有其他三种页面样式:

empty:不显示页眉和页脚plain:这是默认样式;不显示页眉;页脚中显示居中的页码myheadings:不显示页脚;页眉中显示页码,偶数页的页码显示在右侧,奇数页的页码显示在左侧;除了页码之外,还显示用户自定义的信息;还有一个例外,在每一章的第一页,不显示页眉,页脚显示居中的页码。

设置当前页的页面样式

有些时候我们只需要改变某一页的页面样式,例如,创建一个空页,或者删除当前页的页眉和页脚等:

\chapter{Sample Chapter}

\thispagestyle{empty}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do

eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim

}ad minim veniam, quis nostrud exercitation ullamco laboris nisi

ut aliquip ex ea commodo consequat. Duis aute irure dolor in

reprehenderit in voluptate velit es...

\end{document}

当然,你可以选择除了empty之外的任何样式。

自定义单边文档的页面样式

你可以使用fancyhdr来改变默认的页面结构。下面给出一个例子:

\documentclass{article}

\usepackage[english]{babel}

\usepackage[utf8]{inputenc}

\usepackage{fancyhdr}

\pagestyle{fancy}

\fancyhf{}

\rhead{Overleaf}

\lhead{Guides and tutorials}

\rfoot{Page \thepage}

\begin{document}

\section{First Section}

Hello, here is some text without a meaning. This

text should show what a printed text will look like at

this place. If you read this text, you will get no information.

Really? Is there no information? Is there a difference between

this ...

\end{document}

为了自定义文档中的页眉和页脚,你需要首先引入fancyhdr包:

\usepackage{fancyhdr}

然后,设置"fancy"样式:\pagestyle{fancy}。命令\fancyhf{}会清除页眉和页脚。如果不使用这个命令,默认的“plain”样式会被使用。

下面,我们介绍其他命令的用法:

\rhead{Overleaf} 在页眉的右侧显示大括号之中的文字。

\lhead{Guides and tutorials} 在页眉的左侧显示大括号之中的文字。

\chead{} 与上面的例子相似,大括号之中的文字会居中显示。

\rfoot{Page \thepage} 在页脚右侧显示文字“Page”以及当前页的页码(\thepage)。文末列出了一系列自动生成内容的命令(例如章节编码等)。

\lfoot{ } 在页脚左侧显示大括号之中的文字。

\cfoot{ } 在页脚中间显示大括号之中的文字。

自定义双边文档的页面样式

如果你的文档是双边的(即奇数页和偶数页的样式不同,例如书籍)且你希望自定义页眉和页脚,那么你可以使用\fancyhead和\fancyfoot命令来做到这一点。下面给出一个例子:

\documentclass[a4paper,12pt,twoside]{book}

\usepackage[utf8]{inputenc}

\usepackage[english]{babel}

\usepackage{fancyhdr}

\pagestyle{fancy}

\fancyhf{}

\fancyhead[LE,RO]{Overleaf}

\fancyhead[RE,LO]{Guides and tutorials}

\fancyfoot[CE,CO]{\leftmark}

\fancyfoot[LE,RO]{\thepage}

\begin{document}

\chapter{Using different page styles}

Lorem ipsum dolor sit amet, consectetur adipiscing ...

命令的可选参数包括:

E:偶数页O:奇数页L:左侧R:右侧C:居中

例如,\fancyhead[LE,RO]{Overleaf}会在偶数页的页眉左侧显示“Overleaf”,在奇数页的右侧显示“Overleaf”。

页眉和页脚的装饰线

当你使用fancyhdr包的时候,它会在页面显示两种装饰线(分别在页眉和页脚)。页脚的装饰线的宽度被设置为0pt,所以它默认是不可见的。我们可以改变它的宽度:

\documentclass[a4paper,12pt,twoside]{book}

\usepackage[utf8]{inputenc}

\usepackage[english]{babel}

\usepackage{fancyhdr}

\pagestyle{fancy}

\fancyhf{}

\fancyhead[LE,RO]{Overleaf}

\fancyhead[RE,LO]{Guides and tutorials}

\fancyfoot[CE,CO]{\leftmark}

\fancyfoot[LE,RO]{\thepage}

\renewcommand{\headrulewidth}{2pt}

\renewcommand{\footrulewidth}{1pt}

\begin{document}

\chapter{Using different page styles}

Lorem ipsum dolor sit amet, consectetur adipiscing ...

\renewcommand{\headrulewidth}{2pt} 命令将页眉线的宽度设置为2pt

\renewcommand{\footrulewidth}{1pt} 命令将页脚线的宽度设置为1pt

参考指南

你可以使用下面的命令在页眉和页脚中添加自定义信息:

\thepage 显示当前页的页码\thechapter 显示当前章(Chapter)的编码\thesection 显示当前节(Section)的编码\chaptername 显示文字Chapter。如果文档的默认语言不是英语,则显示Chapter的对应语言的翻译文字。\leftmark和\rightmark 显示当前文档类型的最高级文档结构的名字和编码(例如,对于报告reports和书籍books,显示Chapter;对于文章articles,显示Section)。名字大写显示。

🎯 相关推荐

王勤伯:蓝白色的陪练故事
365bet注册

王勤伯:蓝白色的陪练故事

📅 07-28 👀 8031
科目一app哪个好?考驾照科目一下载什么软件?
365英国上市公司

科目一app哪个好?考驾照科目一下载什么软件?

📅 07-10 👀 1979
如何在Windows中检查是否安装了GPU
365英国上市公司

如何在Windows中检查是否安装了GPU

📅 07-15 👀 9927