当前位置: 首页 > 科技观察

LaTeX中的排版(三):排版

时间:2023-03-11 22:31:15 科技观察

本系列介绍LaTeX中的基本排版。第1部分介绍了列表。第2节解释了这些表。在第3部分中,您将了解LaTeX的另一个重要特性:精致灵活的文档布局。本文介绍如何自定义页面布局、目录、页眉部分和页面样式。页面尺寸当您第一次编写LaTeX文档时,您可能已经注意到默认页边距比您想象的要大一些。页边距与指定的纸张类型相关,例如A4、信函和文档类(文章、书籍、报告)等。要修改页边距,有多种选择,最简单的一种是使用fullpage包。这个包设置了页面的主体,使得主体几乎可以占据整个页面。-整页包文件另一种选择是使用几何包。在探索geometry包如何操作页边距之前,首先看一下下面显示的页面尺寸。1inch+\hoffset1inch+\voffset\oddsidemargin=31pt\topmargin=20pt\headheight=12pt\headsep=25pt\textheight=592pt\textwidth=390pt\marginparsep=35pt\marginparwidth=35pt\footskip=30pt使用几何包来设置边距为1英寸,使用下面的例子要更改纸张大小,请使用以下示例:\usepackage[a4paper,total={7in,8in}]{geometry}要更改页面方向,您需要将横向添加到几何选项中,如下所示:\usepackage{geometry}\geometry{a4paper,landscape,margin=1.5indirectory默认情况下,目录的标题是“contents”。有时,您想将标题更改为“目录”,更改目录与??章节第一节之间的垂直间距,或者只是更改文本的颜色。要更改文本,请在序言中添加以下行,将英语替换为所需的语言:\usepackage[english]{babel}\addto\captionsenglish{\renewcommand{\contentsname}{\bfseries{TableofContents}}}To操纵目录和图表、小节和章节列表之间的虚拟间距,使用tocloft包。本文中使用的两个选项是cftbeforesecskip和cftaftertoctitleskip。tocloft包提供了控制目录、图表列表和表格列表排版的方法。-TOCLOFTPACKAGEDOUCMENTATION\usepackage{tocloft}\setlength\ctfbeforesecskip{2pt}\setlength\cftaftertoctitleskip{30pt}默认目录自定义目录边框在文档中使用包hyperref时,目录中的LaTeX章节列表和包含\url的引文都有边框,如下图所示。要删除这些边框,请在序言中包含以下内容,您将看到目录中没有边框。\usepackage{hyperref}\hypersetup{pdfborder={000}}要修改标题部分的字体、样式或颜色,请使用包titlesec。在此示例中,您将更改节、小节和三级小节的字体大小、字体样式和字体颜色。首先,在序言中增加以下内容。\usepackage{titlesec}\titleformat*{\section}{\Huge\bfseries\color{darkblue}}\titleformat*{\subsection}{\huge\bfseries\color{darkblue}}\titleformat*{\subsubsection}{\Large\bfseries\color{darkblue}}仔细看代码,\titleformat*{\section}指定了要使用的节的深度。上面的示例使用了第三个深度。{\Huge\bfseries\color{darkblue}}部分指定字体大小、字体样式和字体颜色。页面样式对于自定义页眉和页脚,请使用fancyhdr。此示例使用此包来修改页面样式、页眉和页脚。下面的代码简要描述了每个选项的作用。\pagestyle{fancy}%让标题出现在每个页面上\fancyhead[L]{}%保留左侧标题空白\fancyhead[C]{}%保留中心标题空白\fancyhead[R]{\leftmark}%添加该部分/chaptertotheheaderright\fancyfoot[L]{StaticContent}%addstatictesttotheleftfooter\fancyfoot[C]{}%keepcenterfooterblank\fancyfoot[R]{\thepage}%添加页码到右页脚\setlength\voffset{-0.25in}%页面边框和页眉之间的空间(1in+space)\setlength\headheight{12pt}%实际页眉的高度。\setlength\headsep{25pt}%页眉和页眉之间的分隔text.\renewcommand{\headrulewidth}{2pt}%addheaderhorizo??ntalline\renewcommand{\footrulewidth}{1pt}%addfooterhorizo??ntalline结果如下:HeaderFooterTips重点放在介绍区如果你想写一个很多TeX文档,您可以根据文档类别创建一个包含所有序言区域的.tex文件并引用此文件。例如,我使用如下所示的structure.tex。$catarticle_structure.tex\usepackage[english]{babel}\addto\captionsenglish{\renewcommand{\contentsname}{\bfseries{\color{darkblue}目录}}}%Relablethecontents%\usepackage[margin=0.5in]{geometry}%指定文档的边距\usepackage[utf8]{inputenc}\usepackage[T1]{fontenc}\usepackage{graphicx}%允许你向文档添加图形\usepackage{hyperref}%允许重定向来自PDF文档的URL\usepackage{fullpage}%格式化内容以利用整页%\usepackage{a4wide}\usepackage[export]{adjustbox}%强制图像位置%\usepackage[section]{placeins}%在一个图中有多个图像\usepackage{tabularx}%用于在表格中包装文本%\usepackage{rotating}\usepackage{multirow}\usepackage{subcaption}%在一个图中有多个图像%\usepackage{smartdiagram}%初始化smartdiagrams\usepackage{enumitem}%管理列表和枚举之间的间距\usepackage{fancyhdr}%,graphicx}%用于每个页面上的标题\pagestyle{fancy}%用于每个页面上的标题%\fancyhf{}\fancyhead[L]{}\fancyhead[C]{}\fancyhead[R]{\leftmark}\fancyfoot[L]{静态内容}%\includegraphics[width=0.02\textwidth]{virgin_voyages.png}}\fancyfoot[C]{}%clearcenter\fancyfoot[R]{\thepage}\setlength\voffset{-0.25in}%页面边框和页眉之间的间距(1in+空格)\setlength\headheight{12pt}%实际页眉的高度。\setlength\headsep{25pt}%页眉和文本之间的分隔。\renewcommand{\headrulewidth}{2pt}%添加水平线\renewcommand{\footrulewidth}{1pt}%添加水平线(页脚)%\renewcommand{\oddsidemargin}{2pt}%调整边距间距%\renewcommand{\pagenumbering}{roman}%变化编号样式%\renewcommand{\hoffset}{20pt}%\usepackage{color}\usepackage[table]{xcolor}\hypersetup{pdfborder={000}}%从目录中删除红色边框%\usepackage{wasysym}%addcheckbox%\newcommand\insq[1]{%%\Square\#1\quad%%}%指定添加复选框的命令%\usepackage{xcolor}%\usepackage{colortbl}%\definecolor{Gray}{gray}{0.9}%创建新颜色%\definecolor{LightCyan}{rgb}{0.88,1,1}%创建新颜色%\usepackage[first=0,last=9]{lcg}%\newcommand{\ra}{\rand0.\arabic{rand}}%\newcolumntype{g}{>{\columncolor{LightCyan}}c}%创建新列类型g%\usesmartdiagramlibrary{additions}%\setcounter{figure}{0}\setcounter{secnumdepth}{0}%sectionsarelevel1\usepackage{csquotes}%正确的是使用双引号%\usepackage{draftwatermark}%启用水印%\SetWatermarkText{DRAFT}%指定水印文本%\SetWatermarkScale{5}%切换水印大小\usepackage{listings}%添加代码blocks\usepackage{titlesec}%Manipulatesection/subsection\titleformat{\section}{\Huge\bfseries\color{darkblue}}%将部分更新为粗体,颜色为蓝色\titleformat{\subsection}{\huge\bfseries\color{darkblue}}%将小节更新为粗体ecolorblue\titleformat*{\subsubsection}{\Large\bfseries\color{darkblue}}%将子小节更新为粗体颜色blue\usepackage[toc]{appendix}%在TOC\usepackage{xcolor}\usepackage中包含附录{tocloft}%用于操作目录虚拟间距%\setlength\cftparskip{-2pt}\setlength\cftbeforesecskip{2pt}%部分之间的间距\setlength\cftaftertoctitleskip{30pt}%第一部分和文本之间的空间``目录''\definecolor{navyblue}{rgb}{0.0,0.0,0.5}\definecolor{zaffre}{rgb}{0.0,0.08,0.66}\definecolor{white}{rgb}{1.0,1.0,1.0}\definecolor{darkblue}{rgb}{0.0,0.2,0.6}\definecolor{darkgray}{rgb}{0.66,0.66,0.66}\definecolor{lightgray}{rgb}{0.83,0.83,0.83}%\pagenumbering{roman}在您的文章中,参考structure.tex文件,如下例所示:\documentclass[a4paper,11pt]{article}\input{/path_to_structure.tex}}\begin{document}......\end{document}添加水印要在LaTeX文档中启用水印,请使用draftwatermark包下面的代码片段和图像演示了如何向文档添加水印。默认情况下,水印颜色为灰色,可以修改为您想要的颜色。\usepackage{draftwatermark}\SetWatermarkText{\color{red}Classified}%addwatermarktext\SetWatermarkScale{4}%specifythesizeofthetext结论在本系列中,您了解了LaTeX提供的一些基本但丰富的功能,这些功能可用于自定义文档以满足您的需要或文档的受众。在LaTeX的海洋中,还有很多包需要你自己去探索。