当前位置:首页 >焦点 >LaTeX 排版(3):排版 第 1 部分 介绍了列表

LaTeX 排版(3):排版 第 1 部分 介绍了列表

2024-06-30 17:25:49 [百科] 来源:避面尹邢网

LaTeX 排版(3):排版

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

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

LaTeX 排版(3):排版 第 1 部分 介绍了列表

页面维度

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

LaTeX 排版(3):排版 第 1 部分 介绍了列表

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

LaTeX 排版(3):排版 第 1 部分 介绍了列表

—— 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 英寸,请使用以下示例

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

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

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

 

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

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

 

目录

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

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

  1. \usepackage[english]{ babel}
  2. \addto\captionsenglish{
  3. \renewcommand{ \contentsname}
  4. { \bfseries{ Table of Contents}}}

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

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

—— TOCLOFT PACKAGE DOUCMENTATION

  1. \usepackage{ tocloft}
  2. \setlength\ctfbeforesecskip{ 2pt}
  3. \setlength\cftaftertoctitleskip{ 30pt}

 

默认目录

 

定制目录

边框

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

 

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

  1. \usepackage{ hyperref}
  2. \hypersetup{ pdfborder = { 0 0 0}}

要修改标题部分的字体、样式或颜色,请使用程序包 titlesec。在本例中,你将更改节、子节和三级子节的字体大小、字体样式和字体颜色。首先,在导言区中增加以下内容。

  1. \usepackage{ titlesec}
  2. \titleformat*{ \section}{ \Huge\bfseries\color{ darkblue}}
  3. \titleformat*{ \subsection}{ \huge\bfseries\color{ darkblue}}
  4. \titleformat*{ \subsubsection}{ \Large\bfseries\color{ darkblue}}

仔细看看代码,\titleformat*{ \section} 指定要使用的节的深度。上面的示例最多使用第三个深度。{ \Huge\bfseries\color{ darkblue}} 部分指定字体大小、字体样式和字体颜色。

页面样式

要自定义的页眉和页脚,请使用 fancyhdr。此示例使用此包修改页面样式、页眉和页脚。下面的代码简要描述了每个选项的作用。

  1. \pagestyle{ fancy} %for header to be on each page
  2. \fancyhead[L]{ } %keep left header blank
  3. \fancyhead[C]{ } %keep centre header blank
  4. \fancyhead[R]{ \leftmark} %add the section/chapter to the header right
  5. \fancyfoot[L]{ Static Content} %add static test to the left footer
  6. \fancyfoot[C]{ } %keep centre footer blank
  7. \fancyfoot[R]{ \thepage} %add the page number to the right footer
  8. \setlength\voffset{ -0.25in} %space between page border and header (1in + space)
  9. \setlength\headheight{ 12pt} %height of the actual header.
  10. \setlength\headsep{ 25pt} %separation between header and text.
  11. \renewcommand{ \headrulewidth}{ 2pt} % add header horizontal line
  12. \renewcommand{ \footrulewidth}{ 1pt} % add footer horizontal line

结果如下所示:

 

页眉

 

页脚

小贴士

集中导言区

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

  1. $ cat article_structure.tex
  2. \usepackage[english]{ babel}
  3. \addto\captionsenglish{
  4. \renewcommand{ \contentsname}
  5. { \bfseries{ \color{ darkblue}Table of Contents}}
  6. } % Relable the contents
  7. %\usepackage[margin=0.5in]{ geometry} % specifies the margin of the document
  8. \usepackage[utf8]{ inputenc}
  9. \usepackage[T1]{ fontenc}
  10. \usepackage{ graphicx} % allows you to add graphics to the document
  11. \usepackage{ hyperref} % permits redirection of URL from a PDF document
  12. \usepackage{ fullpage} % formate the content to utilise the full page
  13. %\usepackage{ a4wide}
  14. \usepackage[export]{ adjustbox} % to force image position
  15. %\usepackage[section]{ placeins} % to have multiple images in a figure
  16. \usepackage{ tabularx} % for wrapping text in a table
  17. %\usepackage{ rotating}
  18. \usepackage{ multirow}
  19. \usepackage{ subcaption} % to have multiple images in a figure
  20. %\usepackage{ smartdiagram} % initialise smart diagrams
  21. \usepackage{ enumitem} % to manage the spacing between lists and enumeration
  22. \usepackage{ fancyhdr} %, graphicx} %for header to be on each page
  23. \pagestyle{ fancy} %for header to be on each page
  24. %\fancyhf{ }
  25. \fancyhead[L]{ }
  26. \fancyhead[C]{ }
  27. \fancyhead[R]{ \leftmark}
  28. \fancyfoot[L]{ Static Content} %\includegraphics[width=0.02\textwidth]{ virgin_voyages.png}}
  29. \fancyfoot[C]{ } % clear center
  30. \fancyfoot[R]{ \thepage}
  31. \setlength\voffset{ -0.25in} %Space between page border and header (1in + space)
  32. \setlength\headheight{ 12pt} %Height of the actual header.
  33. \setlength\headsep{ 25pt} %Separation between header and text.
  34. \renewcommand{ \headrulewidth}{ 2pt} % adds horizontal line
  35. \renewcommand{ \footrulewidth}{ 1pt} % add horizontal line (footer)
  36. %\renewcommand{ \oddsidemargin}{ 2pt} % adjuct the margin spacing
  37. %\renewcommand{ \pagenumbering}{ roman} % change the numbering style
  38. %\renewcommand{ \hoffset}{ 20pt}
  39. %\usepackage{ color}
  40. \usepackage[table]{ xcolor}
  41. \hypersetup{ pdfborder = { 0 0 0}} % removes the red boarder from the table of content
  42. %\usepackage{ wasysym} %add checkbox
  43. %\newcommand\insq[1]{ %
  44. % \Square\ #1\quad%
  45. %} % specify the command to add checkbox
  46. %\usepackage{ xcolor}
  47. %\usepackage{ colortbl}
  48. %\definecolor{ Gray}{ gray}{ 0.9} % create new colour
  49. %\definecolor{ LightCyan}{ rgb}{ 0.88,1,1} % create new colour
  50. %\usepackage[first=0,last=9]{ lcg}
  51. %\newcommand{ \ra}{ \rand0.\arabic{ rand}}
  52. %\newcolumntype{ g}{ >{ \columncolor{ LightCyan}}c} % create new column type g
  53. %\usesmartdiagramlibrary{ additions}
  54. %\setcounter{ figure}{ 0}
  55. \setcounter{ secnumdepth}{ 0} % sections are level 1
  56. \usepackage{ csquotes} % the proper was of using double quotes
  57. %\usepackage{ draftwatermark} % Enable watermark
  58. %\SetWatermarkText{ DRAFT} % Specify watermark text
  59. %\SetWatermarkScale{ 5} % Toggle watermark size
  60. \usepackage{ listings} % add code blocks
  61. \usepackage{ titlesec} % Manipulate section/subsection
  62. \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
  63. \titleformat*{ \subsubsection}{ \Large\bfseries\color{ darkblue}} % update subsubsections to bold with the colour blue
  64. \usepackage[toc]{ appendix} % Include appendix in TOC
  65. \usepackage{ xcolor}
  66. \usepackage{ tocloft} % For manipulating Table of Content virtical spacing
  67. %\setlength\cftparskip{ -2pt}
  68. \setlength\cftbeforesecskip{ 2pt} %spacing between the sections
  69. \setlength\cftaftertoctitleskip{ 30pt} % space between the first section and the text ``Table of Contents''
  70. \definecolor{ navyblue}{ rgb}{ 0.0,0.0,0.5}
  71. \definecolor{ zaffre}{ rgb}{ 0.0, 0.08, 0.66}
  72. \definecolor{ white}{ rgb}{ 1.0, 1.0, 1.0}
  73. \definecolor{ darkblue}{ rgb}{ 0.0, 0.2, 0.6}
  74. \definecolor{ darkgray}{ rgb}{ 0.66, 0.66, 0.66}
  75. \definecolor{ lightgray}{ rgb}{ 0.83, 0.83, 0.83}
  76. %\pagenumbering{ roman}

在你的文章中,请参考以下示例中所示的方法引用 structure.tex 文件:

  1. \documentclass[a4paper,11pt]{ article}
  2. \input{ /path_to_structure.tex}}
  3. \begin{ document}
  4. ......
  5. \end{ document}

添加水印

要在 LaTeX 文档中启用水印,请使用 draftwatermark 软件包。下面的代码段和图像演示了如何在文档中添加水印。默认情况下,水印颜色为灰色,可以将其修改为所需的颜色。

  1. \usepackage{ draftwatermark}
  2. \SetWatermarkText{ \color{ red}Classified} %add watermark text
  3. \SetWatermarkScale{ 4} %specify the size of the text

 

结论

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

责任编辑:庞桂玉 来源: Linux中国 LaTex排版LaTeX排版

(责任编辑:焦点)

    推荐文章
    热点阅读