里怎么做页眉页脚_Latex的页脚和页眉

本文详细介绍了如何在Latex中利用Fancyhdr宏包自定义页眉和页脚,包括设置页眉页脚的三部分、奇偶页不同样式、修改可用的显示信息等,并给出了具体代码示例。
摘要由CSDN通过智能技术生成

7793a0ad25ffce391853dd9d90dce5aa.png

本文将介绍关于Latex基于Fancyhdr包的页脚和页眉一些配置问题,并给出一些例子和输出结果。


1. Fancy包的功能介绍

fancyhdr宏包允许您在LATEX中以一种简单的方式定制页面页眉和页脚。通过该包可以定义:

  1. 页眉和页脚的三部分
  2. 页眉和页脚的装饰线
  3. 页眉页脚与文本宽度之比
  4. 多行页眉和页脚
  5. 为偶数页和奇数页分别设置页眉和页脚
  6. 不同的页眉和页脚
  7. 不同的页眉和页脚与浮动
  8. 控制字体、大小写显示等。

2. LaTex的页面结构

LATEX文档中的页面是由各种元素构建的,如图1所示。正文包含文档的主要文本以及所谓的浮点数(表和图)。这些页面是由LATEX的输出例程构造的,该例程非常复杂,因此不应该进行修改。LaTex提供了一些包供修改这些参数。下面是有关这些参数的一个例子:

1545d3e0ef3edef4dc172daa978c48b3.png
图2-1 页面元素和当前的参数

LaTex提供了一些有用的样式,但是它们非常有限。通过键入pagestyle{xxx}命令执行。

documentclass{article}
pagestyle{plain}
begin{document}……test!end{document}

b6b66f25139752652ffede9ba6d9dae7.png
图2-2输出结果

d12fee2e120a0f30180874677a7f9f0e.png
图2-3 line 3 plain换为headings


控制奇偶数页不是直接通过用户命令,而是通过修改LATEX输出例程使用的“变量”。因为命令名包含字符“@”,所以应该在包文件中定义它们,可以通过定义表单ps xxx的命令来修改页面样式。或者将它们夹在makeatletter和makeatother命令之间。

pagenumbering命令定义页码的布局。它有一个参数从以下列表:

  • arabic 阿拉伯数字
  • roman l小写的罗马数字
  • Roman 大写的罗马数字
  • alph 小写字母
  • Alph 大写字母
%--------------------导言--------------------%
documentclass{article}
pagestyle{myheadings}%设置页面格式
pagenumbering{Alph}%设置页码格式
%--------------------正文--------------------%
begin{document}
	section{xiaoyeyimier}
	I can swallow a bottle of alcohol and I'll feel like a Godzilla
end{document}

a5edcad0a17444c315c1218811c34ffe.png
图2-4 修改页码的例子

从上面的例子可以看出虽然通过一些命令完成了对页面样式控制,但是,是比较有限的。


3. 使用fancyhdr包

3.1 一个简单的例子

%--------------------导言--------------------%
documentclass{report}
usepackage{fancyhdr}%导入fancyhdr包
usepackage{ctex}%导入ctex包
pagenumbering{Alph}%设置页码格式,大写字母标页
pagestyle{fancy}
fancyhead[L]{左页眉}
fancyhead[R]{右页眉}
fancyhead[L]{中间页眉}
fancyfoot[L]{左页脚}
fancyfoot[C]{thepage}
fancyfoot[R]{右页脚}
renewcommand{headrulewidth}{4pt}%分隔线宽度4磅
renewcommand{footrulewidth}{4pt}
%--------------------正文--------------------%
begin{document}
	section{xiaoyeyimier}
	I can swallow a bottle of alcohol and I'll feel like a Godzilla
end{document}

8c9ace8e13dbfd11159683bdb2e005e2.png

f6ddf7dc775bf0275741c63b630aaa9c.png
图3-1 例1输出结果:thepage宏显示当前的页码

一些解释写在了注释里,其他的请读者自己尝试改动即可了解含义(注:需要导入的ctex和fancyhdr包在一些比较早的LaTex环境中可能需要预先安装)

3.2 奇偶页排版的例子

%--------------------导言--------------------%
documentclass{book}
usepackage{fancyhdr}%导入fancyhdr包
usepackage{ctex}%导入ctex包
pagenumbering{arabic}%设置页码格式,大写字母标页
pagestyle{fancy}
fancyhead{} % 初始化页眉
fancyhead[CO,CE]{xiaoyeyimier}
fancyfoot{} % 初始化页脚
fancyfoot[LO]{奇数页左页脚}
fancyfoot[LE]{偶数页左页脚}
fancyfoot[RO]{奇数页右页脚}
fancyfoot[RE]{偶数页右页脚}

renewcommand{headrulewidth}{4pt}%分隔线宽度4磅
renewcommand{footrulewidth}{4pt}
%--------------------正文--------------------%
begin{document}
	section{xiaoyeyimier}
	I can swallow a bottle of alcohol and I'll feel like a Godzilla
	newpage 
	Better hit the deck like the card dealer
end{document}

命令fancyhead(或fancyfoot)在方括号内的两个参数指定了它们应用于哪些页和(或)部分的页眉(页脚)。

第一个fancyhead命令省略了这个参数,因此适用于所有头字段。一般来说,用于删除默认值或前面的定义。可以在方括号之间使用的选项如下所示。可以将选项组合在一起,这样fancyhead[LE,RO]{text}将为偶数页上的左页眉和奇数页上的右页眉定义字段。如果你没有给出E或O,这个定义就同时适用于两者。(此选项的大小写不敏感)

  • E Even page奇数页
  • O Odd page偶数页
  • L Left field
  • C Center field
  • R Right field

使用fancyhf 就可以使用下面两个参数指定页眉还是页脚,这样页眉页脚都可以用一个命令控制了。

  • H Header
  • F Footer

下面是输出结果

5a89cd7c4c0d64dcce7ef2d1467282f8.png

6c3288446245c00b18ade1ef79617510.png
图3-2 第一页

11917546a089768ece784e5b15fe9a6e.png

ebe6266a7b8d64e00b82874a1c2da7e6.png
图3-3 第二页

3.3 修改可用的显示信息

通常,对于书和报告类文档,在标题中使用Chapter和Section信息(Chapter仅用于单边打印),而对于文章、章节和小节类信息(章节仅用于单边打印)。LATEX用标记机制来记住页面的章节和小节分信息

有两种方法可以使用和更改可用的高级和低级分区信息。

1.l调用宏:leftmark(高)和rightmark(低)包含LATEX处理过的信息,直接使用它们,如第下面一段代码节所示。

%--------------------导言--------------------%
documentclass{book}
usepackage{fancyhdr}%导入fancyhdr包
usepackage{ctex}%导入ctex包

pagenumbering{arabic}%设置页码格式,大写字母标页
pagestyle{fancy}

title{{Godzilla}}
author{小爷一米二}
date{today}

fancyhead{} % 初始化页眉
fancyhead[LE]{textsl{rightmark}}
fancyhead[RO]{textsl{leftmark}}
%fancyfoot{} % 初始化页脚
%fancyfoot[LO]{奇数页左页脚}
%fancyfoot[LE]{偶数页左页脚}
%fancyfoot[RO]{奇数页右页脚}
%fancyfoot[RE]{偶数页右页脚}

renewcommand{headrulewidth}{4pt}%分隔线宽度4磅
renewcommand{footrulewidth}{4pt}

%--------------------正文--------------------%
begin{document}
	maketitle
	tableofcontents %—— 制作目录(目录是根据标题自动生成的)
	
	chapter{Godzilla}
	Eminem,Juice WRLD
	newpage %新另起一页
	section{Verse 1}
	noindent Uh, you're a monster
	I can swallow a bottle of alcohol and I'll feel like Godzilla
	Better hit the deck like the card dealer
	My whole squad's in here, walkin' around the party
	A cross between a zombie apocalypse and big Bobby "The
	Brain" Heenan which is probably the
	Same reason I wrestle with mania
	Shady's in this bitch, I'm posse'd up
	Consider it to cross mea costly mistake
	If they sleepin' on me, thehoes better get insomnia
	ADHD, hydroxycut
	Pass the Courvoisi' (Hey, hey)
	In AA with an AK, melee, finna set it like a playdate
	Better vacate, retreat like a vacay, mayday
	This beat is cray-cray, Ray J, H-A, H-A, H-A
	Laughing all the way to the bank, I spray flames
	They cannot tame or placate the
	section{Hook 1}
	noindent Monster
	You get in my way, I'ma feed you to the monster (Yeah)
	I'm normal during the day, but at night, turn to a monster (Yeah)
	When the moon shines like Ice Road Truckers
	I look like a villain outta those blockbusters
	Godzilla, fire spitter, monster
	Blood on the dance floor, and on the Louis V carpet
	Fire, Godzilla, fire, monster
	Blood on the dance floor, and on the Louis V carpet
	section{Verse 2}
	noindent I'm just a product of Slick Rick and Onyx, told 'em lick the balls
	Had 'em just appalled at so many things that pissed 'em off
	It's impossible to list 'em all
	And in the midst of all this
	I'm in a mental hospital with a crystal ball
	Tryna see, will I still be like this tomorrow?
	Risperdal, voices whisper
	My fist is balled back up against the wall, pencil drawn
	This is just the song to go ballistic on
	You just pulled a pistol on the guy with the missile launcher
	I'm just a Loch Ness, the mythological
	Quick to tell a bitch screw off like a fifth of Vodka
	When you twist the top of the bottle, I'm a
	section{Hook 2}
	noindent Monster
	You get in my way, I'ma feed you to the monster (Yeah)
	I'm normal during the day, but at night, turn to a monster (Yeah)
	When the moon shines like Ice Road Truckers
	I look like a villain outta those blockbusters
	Godzilla, fire spitter, monster
	Blood on the dance floor, and on the Louis V carpet
	Fire, Godzilla, fire, monster
	Blood on the dance floor, and on the Louis V carpet
	section{Verse 3}
	noindent If you never gave a damn, raise your hand
	'Cause I'm about to set trip, vacation plans
	I'm on point like my index is, so all you will ever get is
	The motherfuckin' finger (Finger), prostate exam ('Xam)
	How can I have all these fans and perspire?
	Like a liar's pants, I'm on fire
	And I got no plans to retire and I'm still the man you admire
	These chicks are spazzin' out, I only get more handsome and flier
	I got 'em passin' out like what you do when you hand someone flyers
	And what goes around comes around just like the blades on the chainsaw
	'CauseI caught the flap of my dollar stack right off the bat like a baseball
	Like kidding, bitch I got them racks with so much ease that they call me Diddy
	'Cause I make bands and I call getting cheese a cakewalk (Cheesecake, yeah)
	Bitch, I'm a player, I'm too motherfuckin' stingy for Cher
	Won't even lend you an ear ain't even pretending to care
	But I tell a bitch I'll marry her if she'll bury her
	Face on my genital area, the original Richard Ramirez
	Christian Rivera, 'cause my lyrics never sit well
	So they wanna give me the chair
	Like a paraplegic, and it's scary, call it Harry Caray
	'Cause e'ry Tom and Dick and Harry carry a Merriam motherfuckin' dictionary
	On 'em swearing up and down they can spit, this shit's hilarious
	It's time to put these bitches in the obituary column
	We wouldn't see eye to eye with a staring problem
	Get the shaft like a steering column (Mark Jack)
	Trigger happy, pack heat, but it's black ink
	Evil half of the Bad Meets
	Evil, that means take a back seat
	Take it back to Fat Beats with a maxi, single
	Look at my rap sheet, what attracts these people
	Is my 'Gangsta Bitch' like Apache with a catchy jingle
	I stack chips, you barely got a half-eaten Cheeto
	Fill 'em with the venom and eliminate 'em
	Other words, I Minute Maid 'em
	I don't want to hurt 'em, but I did 'em in a fit of rage
	I'm murderin' again, nobody will evade him
	Finna kill 'em and dump all the fuckin' bodies in the lake
	Obliterating everything, incinerate and renegade 'em
	And I make anybody who want it with the pen afraid
	But don't nobody want it, but they're gonna get it anyway
	'Cause I'm beginnin' to feel like I'm mentally ill
	I'm Attila, kill or be killed, I'm a killer bee, the vanilla gorilla
	You're bringin' the killer within me out of me
	You don't want to be the enemy of the demon who went in me
	And be on the receivin' end of me, what stupidity it'd be
	Every bit of me's the epitome of a spitter
	When I'm in the vicinity, motherfucker, you better duck
	Or you finna be dead the minute you run into me
	A hundred percent of you is a fifth of a percent of me
	I'm 'bout to fuckin' finish you bitch, I'm unfadable
	You wanna battle, I'm available, I'm blowin' up like an inflatable
	I'm undebatable, I'm unavoidable, I'm unevadable
	I'm on the toilet bowl, I got a trailer full of money and I'm paid in full
	I'm not afraid to pull the—
	Man, stop
	Look what I'm plannin', hah
end{document}

296c9227231546522476452abeeea192.png
图3-4 第6页输出结果

751b01ee8463c2c8fc1cbc4a6ed8900e.png
图3-5 第七页输出结果

这是一段Eminem的歌词,今后的文本都将采用这段文本。如无特殊改动将不再在代码块声明。

leftmark对应Section信息参数,rightmark对应Chapter信息参数,如果在当前页面上没有这些参数,它们将从前一个页面继承。当然读者也可以去redefine它们,必须将重新定义放在pagestyle{fancy}的第一次调用之后,因为pagestyle{fancy}会设置默认值。

eg:

renewcommand{sectionmark}[1]{markright{thesection- #1}}

将上面这条指令加入程序,就可以实现修改section样式

01f5b4ccaeb6f2bf4ee7f5a10a0b8437.png
图3-6 修改页眉的样式

同理可以实现修改Chapter信息的样式。

常见的页眉页脚先写到这里,等有空慢慢填坑--2020/3/21

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值