LaTeX 排版(3):排版
创始人
2024-03-02 06:53:49
0

系列 介绍了 LaTeX 中的基本格式。第 1 部分 介绍了列表。第 2 部分 阐述了表格。在第 3 部分中,你将了解 LaTeX 的另一个重要特性:细腻灵活的文档排版。本文介绍如何自定义页面布局、目录、标题部分和页面样式。

页面维度

当你第一次编写 LaTeX 文档时,你可能已经注意到默认边距比你想象的要大一些。页边距与指定的纸张类型有关,例如 A4、letter 和 documentclass(article、book、report) 等等。要修改页边距,有几个选项,最简单的选项之一是使用 fullpage 包。

该软件包设置页面的主体,可以使主体几乎占满整个页面。

—— FULLPAGE PACKAGE DOCUMENTATION

另一个选择是使用 geometry 包。在探索 geometry 包如何操纵页边距之前,请首先查看如下所示的页面尺寸。

  1. 1 英寸 + \hoffset
  2. 1 英寸 + \voffset
  3. \oddsidemargin = 31pt
  4. \topmargin = 20pt
  5. \headheight = 12pt
  6. \headsep = 25pt
  7. \textheight = 592pt
  8. \textwidth = 390pt
  9. \marginparsep = 35pt
  10. \marginparwidth = 35pt
  11. \footskip = 30pt

要使用 geometry 包将边距设置为 1 英寸,请使用以下示例

\usepackage{geometry}
\geometry{a4paper, margin=1in}

除上述示例外,geometry 命令还可以修改纸张尺寸和方向。要更改纸张尺寸,请使用以下示例:

\usepackage[a4paper, total={7in, 8in}]{geometry}

要更改页面方向,需要将横向(landscape)添加到 geometery 选项中,如下所示:

\usepackage{geometery}
\geometry{a4paper, landscape, margin=1.5in

目录

默认情况下,目录的标题为 “contents”。有时,你想将标题更改为 “Table of Content”,更改目录和章节第一节之间的垂直间距,或者只更改文本的颜色。

若要更改文本,请在导言区中添加以下行,用所需语言替换英语(english):

\usepackage[english]{babel}
\addto\captionsenglish{
\renewcommand{\contentsname}
{\bfseries{Table of Contents}}}

要操纵目录与图、小节和章节列表之间的虚拟间距,请使用 tocloft 软件包。本文中使用的两个选项是 cftbeforesecskipcftaftertoctitleskip

tocloft 包提供了控制目录、图表列表和表格列表的排版方法。

—— TOCLOFT PACKAGE DOUCMENTATION

\usepackage{tocloft}
\setlength\ctfbeforesecskip{2pt}
\setlength\cftaftertoctitleskip{30pt}

默认目录

定制目录

边框

在文档中使用包 hyperref 时,目录中的 LaTeX 章节列表和包含 \url 的引用都有边框,如下图所示。

要删除这些边框,请在导言区中包括以下内容,你将看到目录中没有任何边框。

\usepackage{hyperref}
\hypersetup{ pdfborder = {0 0 0}}

要修改标题部分的字体、样式或颜色,请使用程序包 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} %for header to be on each page
\fancyhead[L]{} %keep left header blank
\fancyhead[C]{} %keep centre header blank
\fancyhead[R]{\leftmark} %add the section/chapter to the header right
\fancyfoot[L]{Static Content} %add static test to the left footer
\fancyfoot[C]{} %keep centre footer blank
\fancyfoot[R]{\thepage} %add the page number to the right footer
\setlength\voffset{-0.25in} %space between page border and header (1in + space)
\setlength\headheight{12pt} %height of the actual header.
\setlength\headsep{25pt} %separation between header and text.
\renewcommand{\headrulewidth}{2pt} % add header horizontal line
\renewcommand{\footrulewidth}{1pt} % add footer horizontal line

结果如下所示:

页眉

页脚

小贴士

集中导言区

如果要编写许多 TeX 文档,可以根据文档类别创建一个包含所有导言区的 .tex 文件并引用此文件。例如,我使用结构 .tex 如下所示。

$ cat article_structure.tex
\usepackage[english]{babel}
\addto\captionsenglish{
\renewcommand{\contentsname}
{\bfseries{\color{darkblue}Table of Contents}}
} % Relable the contents
%\usepackage[margin=0.5in]{geometry} % specifies the margin of the document
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx} % allows you to add graphics to the document
\usepackage{hyperref} % permits redirection of URL from a PDF document
\usepackage{fullpage} % formate the content to utilise the full page
%\usepackage{a4wide}
\usepackage[export]{adjustbox} % to force image position
%\usepackage[section]{placeins} % to have multiple images in a figure
\usepackage{tabularx} % for wrapping text in a table
%\usepackage{rotating}
\usepackage{multirow}
\usepackage{subcaption} % to have multiple images in a figure
%\usepackage{smartdiagram} % initialise smart diagrams
\usepackage{enumitem} % to manage the spacing between lists and enumeration
\usepackage{fancyhdr} %, graphicx} %for header to be on each page
\pagestyle{fancy} %for header to be on each page
%\fancyhf{}
\fancyhead[L]{}
\fancyhead[C]{}
\fancyhead[R]{\leftmark}
\fancyfoot[L]{Static Content} %\includegraphics[width=0.02\textwidth]{virgin_voyages.png}}
\fancyfoot[C]{} % clear center
\fancyfoot[R]{\thepage}
\setlength\voffset{-0.25in} %Space between page border and header (1in + space)
\setlength\headheight{12pt} %Height of the actual header.
\setlength\headsep{25pt} %Separation between header and text.
\renewcommand{\headrulewidth}{2pt} % adds horizontal line
\renewcommand{\footrulewidth}{1pt} % add horizontal line (footer)
%\renewcommand{\oddsidemargin}{2pt} % adjuct the margin spacing
%\renewcommand{\pagenumbering}{roman} % change the numbering style
%\renewcommand{\hoffset}{20pt}
%\usepackage{color}
\usepackage[table]{xcolor}
\hypersetup{ pdfborder = {0 0 0}} % removes the red boarder from the table of content
%\usepackage{wasysym} %add checkbox
%\newcommand\insq[1]{%
% \Square\ #1\quad%
%} % specify the command to add checkbox
%\usepackage{xcolor}
%\usepackage{colortbl}
%\definecolor{Gray}{gray}{0.9} % create new colour
%\definecolor{LightCyan}{rgb}{0.88,1,1} % create new colour
%\usepackage[first=0,last=9]{lcg}
%\newcommand{\ra}{\rand0.\arabic{rand}}
%\newcolumntype{g}{>{\columncolor{LightCyan}}c} % create new column type g
%\usesmartdiagramlibrary{additions}
%\setcounter{figure}{0}
\setcounter{secnumdepth}{0} % sections are level 1
\usepackage{csquotes} % the proper was of using double quotes
%\usepackage{draftwatermark} % Enable watermark
%\SetWatermarkText{DRAFT} % Specify watermark text
%\SetWatermarkScale{5} % Toggle watermark size
\usepackage{listings} % add code blocks
\usepackage{titlesec} % Manipulate section/subsection
\titleformat{\section}{\Huge\bfseries\color{darkblue}} % update sections to bold with the colour blue \titleformat{\subsection}{\huge\bfseries\color{darkblue}} % update subsections to bold with the colour blue
\titleformat*{\subsubsection}{\Large\bfseries\color{darkblue}} % update subsubsections to bold with the colour blue
\usepackage[toc]{appendix} % Include appendix in TOC
\usepackage{xcolor}
\usepackage{tocloft} % For manipulating Table of Content virtical spacing
%\setlength\cftparskip{-2pt}
\setlength\cftbeforesecskip{2pt} %spacing between the sections
\setlength\cftaftertoctitleskip{30pt} % space between the first section and the text ``Table of Contents''
\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} %add watermark text 
\SetWatermarkScale{4} %specify the size of the text

结论

在本系列中,你了解了 LaTeX 提供的一些基本但丰富的功能,这些功能可用于自定义文档以满足你的需要或将文档呈现给的受众。LaTeX 海洋中,还有许多软件包需要大家自行去探索。


via: https://fedoramagazine.org/latex-typesetting-part-3-formatting/

作者:Earl Ramirez 选题:Chao-zhi 译者:Chao-zhi 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

相关内容

AI撰写的科研论文通过了同...
最新发表于《自然》杂志的一项研究显示,一个名为“AI科学家”的系统...
2026-04-01 15:15:16
机器学习 - 理论 - L...
机器学习 - 理论 -广义线性模型 前言广义线性模型定义ÿ...
2025-05-28 18:40:31
不同的LaTex编辑器是否...
不同的LaTex编辑器是可以相互兼容的,因为LaTex语言本身是一...
2025-01-08 16:01:27
不能使用Weave渲染LA...
如果您无法使用Weave将LATEX输出渲染为正确的格式,请确保以...
2024-12-27 07:00:46
避免在LaTeX中使用Ma...
在LaTeX中使用Maxima的tex函数时,有时会产生多余的括号...
2024-12-17 08:01:36
biblatex引用问题:...
这个问题通常是由于引用的文献未在参考文献列表中或引用标签有误而引起...
2024-12-11 19:02:03

热门资讯

“Linux 中国” 开源社区... 这是一个艰难的决定 —— 这不是调侃,而是当你真正做出改变了你十几年生活轨迹的决定时,你就会明白这个...
硬核观察 #1263 德国铁路... #1 德国铁路公司招聘 Windows for Workgroups 3.11 管理员该职位要求了解...
人工智能教程(七):Sciki... 在本系列的 上一篇文章 中,我们用 TensorFlow 构建了第一个神经网络,然后还通过 Kera...
关闭 WSL 中正在运行的 L... 以下是使用 WSL 关闭在 Windows 内运行的 Linux 系统的不同方法。你使用 WSL 在...
MX Linux 23.2 “... 最新的 MX Linux 23.2 小版本更新带来了基本的改进和新增功能。MX Linux 推出了 ...
硬核观察 #1262 网络上最... #1 网络上最古老的软件存档库之一即将关闭美国新墨西哥州立大学(NMSU)最近宣布,即将于 2024...
如何在 RHEL 上通过绑定配... 在 Linux 中,你可以根据自己的需要创建高级网络设置,如 网络绑定 Network Bondin...
Linux Matrix 消息... Matrix 用户可以升级 Fractal 6 了!Fractal 是目前 最好的 Matrix 客...
如何通过 VLC 使用字幕 使用 VLC 媒体播放器播放和管理字幕的新手指南。我是一个超级动漫迷,如果你想观看最新的剧集,那么你...
硬核观察 #1261 X 计划... #1 X 计划在奥斯汀建立内容审核总部据报道,该部门将招聘 100 名全职员工,将主要关注 CSE ...