LateX正文与首页页眉线分别为单双线的设置方法

转自:http://blog.sina.com.cn/s/blog_5e16f1770100me8u.html

说明:正文页眉格式\pagestyle{fancy},首页(标题页)\fancypagestyle{plain}



我们知道使用fancyhdr宏包可以很轻松的设置首页(标题页)与正文页眉不同,这其中也包
括页眉修饰线,但fancyhdr所能添加的页眉修饰线只是单线,所以用它实现的首页与正文
页眉修饰线线的不同也仅限于线的粗细,使用双线页眉修饰线的一段经典代码是这样的:


\newcommand{\makeheadrule}{%
\makebox[0pt][l]{\rule[0.55\baselineskip]{\headwidth}{0.4pt}}%
\rule[0.7\baselineskip]{\headwidth}{0.4pt}}
\renewcommand{\headrule}{%
{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
\makeheadrule}}
\makeatother


但是这样以后你会发现,无论首页还是正文都是同样的双线了,你无法分别进行设置,由
于找不到页眉画线命令\headrule的源代码,所以很难理解上面的代码中的@fancyplain,
\headrulewidth,\plainheadrulewidth是怎么定义的,又是怎么工作的,苦思良久,我终
于找到了一个不错的办法,下面是代码及解释:


\usepackage{ifthen}%这个宏包提供逻辑判断命令


\newboolean{first}%定义一个布尔变量用于判断是否为首页
\setboolean{first}{true}%设定fist变量初值为true


%正文页眉页脚设定
\pagestyle{fancy}
\fancyhf{}
\lhead{} \chead{} \rhead{}
\lfoot{} \cfoot{-~\thepage~-} \rfoot{}


%首页页眉页脚设定
\fancypagestyle{plain}{%
\setboolean{first}{false}%在palin样式的定义中将first重置为false
\lhead{} \chead{} \rhead{}
\lfoot{} \cfoot{-~\thepage~-} \rfoot{}
}


\newcommand{\makefirstpageheadrule}{%定义首页页眉线绘制命令,这里为等宽双线
\makebox[0pt][l]{\rule[0.55\baselineskip]{\headwidth}{0.4pt}}%
\rule[0.7\baselineskip]{\headwidth}{0.4pt}}


\newcommand{\makeheadrule}{%定义正文页页眉线绘制命令,单线
\rule[0.7\baselineskip]{\headwidth}{0.4pt}}


\renewcommand{\headrule}{%重定义headrule命令
\ifthenelse{\boolean{first}}{\makeheadrule}{\makefirstpageheadrule}%
}%根据布尔变量first为true或false分别执行不同的页眉线绘制命令


……


\maketitle
\thispagestyle{plain}
……


一点感想,tex只有你想不到的,没有做不到的!

猜你喜欢

转载自blog.csdn.net/tsroad/article/details/52006672