使用 titlesec 宏包设置标题格式

sunxphere posted @ 2010年3月11日 16:39 , 212 阅读
<p>在 <a href="http://mlsx.xplore.cn/tag/xelatex" rel="tag nofollow" title="标签 xelatex 下的日志">xelatex</a> 中使用 \usepackage 指令使用 titlesec 宏包时,可以指定一些格式选项,如下:<br>\usepackage[center]{titlesec}<br>其中 center 可使标题居中,还可设为 raggedleft (居左,默认), raggedright (居右)。<br>标题由标签与标题内容构成,其格式通常在 <a href="http://mlsx.xplore.cn/tag/xelatex" rel="tag nofollow" title="标签 xelatex 下的日志">xelatex</a> 文档导言区通过 titlesec 宏包提供的指令 \titleformat 进行设定。 \titleformat 指令用法如下:<br>\titleformat{command}[shape]{format}{label}{sep}{before}[after]<br>各参数含义如下:<br><span></span><br>command 是要重新定义的各种标题命令,比如 \part,\chapter,\section,\subsection,\subsubsection,\paragraph,\subparagraph等;<br>shape 是用来设定段落形状的,可选的参数有 hang 、 block 、 display 等,详见 titlesec 文档,位于: <br>$TEXLIVE/$VERSION/texmf-dist/doc/<a href="http://mlsx.xplore.cn/tag/latex" rel="tag nofollow" title="标签 latex 下的日志">latex</a>/titlesec<br>format 用于定义标题外观,比如使标题居中、字体加粗等;<br>label 用于定义定义标题的标签,就是标题内容前面的标号;<br>sep 定义标题的标签与标题内容之间的间隔距离。<br>before 用于在标题内容前再加些内容;<br>after 用于在标题内容后再加些内容。<br>这个指令看似很复杂,但在实际应用中,通常只使用它的几个参数而已。比如,要把文档中的章标题格式由默认的 “Chapter xxx 标题内容” 修改为 “第 xxx 章 标题内容” 格式,如此这般即可:<br>\titleformat{\chapter}{\centering\Huge\bfseries}{第\,\thechapter\,章}{1em}{}<br>其 中, shape 、 before 、 after 参 数 都 被 省 略 掉 了。 format 参 数 将章标题设置为居中( \centering )显示、字号为 \Huge,字体被加粗显示 \bfseries ;在设置 subsection 格式,未采用居中,而是采用默认的居左,另外将标题的字号也降了一级( \large )。 label 参数将标题的标签设置为 “第 xxx 章”格式。 sep 参数设置标签与标题内容之间以一个字(1em)的宽度为间隔。以上设置的章标题效果如下图所示:<br><img style="width:245px;height:76px" src="http://www.google.com/base_media?hl=en&amp;fact=12e&amp;size=3&amp;q=http://www.is-programmer.com/user_files/lyanry/Image/latex-chapter-title1.png&amp;dhm=29ca03fe"><br>如果为上面设置章标题的命令添加一个 shape 参数 “display”,如下:<br>\titleformat{\chapter}[display]{\Huge\bfseries}{第\,\thechapter\,章}{1em}{}<br>这样设置后的章标题效果如下图所示。<br><img style="width:245px;height:94px" src="http://www.google.com/base_media?hl=en&amp;fact=12e&amp;size=3&amp;q=http://www.is-programmer.com/user_files/lyanry/Image/latex-chapter-title2.png&amp;dhm=f66ff448"><br>只要弄明白了 \titleformat 用法,基本上可以实现 <a href="http://mlsx.xplore.cn/tag/xelatex" rel="tag nofollow" title="标签 xelatex 下的日志">xelatex</a> 排版时将文档的章节标题修改为符合中文阅读习惯的格式。<br>使用 fancyhdr 设置页眉页脚<br>在 <a href="http://mlsx.xplore.cn/tag/xelatex" rel="tag nofollow" title="标签 xelatex 下的日志">xelatex</a> 文档导言区使用以下指令可载入宏包 fancyhdr,并将页眉页脚风格设置为 fancy:<br>\usepackage{fancyhdr}<br> \pagestyle{fancy}<br>fancyhdr 宏包将页面分为奇数页(Odd page)和偶数页(Even page),将页眉与页脚各分为三个区域,分别称为左区(Left field)、中区(Center field)和右区(Right field)。这三个区域之间没有分界线,左区中的内容会左对齐在页眉或页脚的左边界,放在右区的内容会对齐在页眉或页脚的右边界,中区内容在整个页眉或页脚区域内居中放置。各区之中的内容不可过长,以避免各区之间发生重叠现象。另外,在默认情况下会显示页眉线,宽度为 0.4pt;页脚线宽都为 0pt,意即不显示。<br>设置页眉的命令为 \fancyhead,设置页脚的命令为 \fancyfoot,其用法如下:<br>\fancyhead[选项参数] {内容}<br> \fancyfoot[选项参数] {内容}<br>\fancyhead 的选项参数页眉或页脚的区域与奇(偶)数页标记的组合,其中页眉(脚)区域用 L (左),C (中),R( 右) 表示,奇数页与偶数页分别用字母 O,E 表示。<br>下面来做一个例子,对于 book 格式的 <a href="http://mlsx.xplore.cn/tag/xelatex" rel="tag nofollow" title="标签 xelatex 下的日志">xelatex</a> 文档,让偶数右区域显示章标题,其左区域显示页码,中间区域为空;让奇数页的页眉左区域显示节标题,其右区域显示页码,其中间区域为空;页脚为空。这个可以在文档导言区中采用以下指令实现:<br> </p><div><ol title="Double click to hide line number."><li>&amp;#92;renewcommand{&amp;#92;chaptermark}&amp;#91;1&amp;#93;{&amp;#92;markboth{&amp;#92;small 第&amp;#92;,&amp;#92;thechapter&amp;#92;,章&amp;#92;quad #1}{}}</li> <li> &amp;#92;renewcommand{&amp;#92;sectionmark}&amp;#91;1&amp;#93;{&amp;#92;markright{&amp;#92;small&amp;#92;thesection&amp;#92;quad #1}{}}</li> <li> </li> <li> &amp;#92;fancyhf{}</li> <li> &amp;#92;fancyhead&amp;#91;ER&amp;#93;{&amp;#92;leftmark}</li> <li> &amp;#92;fancyhead&amp;#91;OL&amp;#93;{&amp;#92;rightmark}</li> <li> &amp;#92;fancyhead&amp;#91;EL,OR&amp;#93;{$&amp;#92;cdot$&amp;#92; &amp;#92;thepage&amp;#92; $&amp;#92;cdot$}</li> <li> &amp;#92;renewcommand{&amp;#92;headrulewidth}{0.4pt}</li></ol></div> <p><br>\fancyhf{} 命令可将已设或页眉页脚的默认设置清空。<br>重新定义了 \chaptermark 与 \sectionmark,这两个重定义一定要记住放在 \pagestyle{fancy}之后,因为在 fancyhdr 宏包中对这两个命令重新进行了定义,在 \pagestyle{fancy} 之后重定义它们就可将 fancyhdr 中的相应命令覆盖掉。<br>还需要解释的是 \leftmark 与 \rightmark,它们分别表示页眉左区域内容与右区域内容。在 book 格式文档中,\leftmark 默认为当前的章标题,\rightmakr 默认为当前的节标题;对于 article 格式文档而言,\leftmark 表示当前节标题,\rightmark 表示当前小节标题。<br>okay,现在看看输出的文档,是不是稍微专业了一些?</p>
  • 无匹配
  • 无匹配

登录 *


loading captcha image...
(输入验证码)