文本格式化
本章介绍 LaTeX 中的文本格式化,包括字体样式、字号、段落格式等内容。
字体样式
字体系列
LaTeX 提供了多种字体样式命令:
文本命令
\textbf{粗体}
\textit{斜体}
\texttt{等宽字体}
\textsc{小型大写}
\textsf{无衬线字体}
\textrm{衬线字体}
\textsl{倾斜字体}
\underline{下划线}
声明命令
{\bfseries 粗体}
{\itshape 斜体}
{\ttfamily 等宽字体}
{\scshape 小型大写}
{\sffamily 无衬线字体}
{\rmfamily 衬线字体}
{\slshape 倾斜字体}
组合样式
\textbf{\textit{粗斜体}}
\textit{\textbf{粗斜体}}
强调
\emph{强调文本} % 在正常文本中为斜体,在斜体文本中为正体
字号
相对字号
{\tiny 最小}
{\scriptsize 更小}
{\footnotesize 脚注大小}
{\small 小}
{\normalsize 正常}
{\large 大}
{\Large 更大}
{\LARGE 很大}
{\huge 巨大}
{\Huge 最大}
绝对字号
在文档类选项中设置:
\documentclass[10pt]{article}
\documentclass[11pt]{article}
\documentclass[12pt]{article}
字号命令
\fontsize{14pt}{16pt}\selectfont % 14pt 字体,16pt 行距
颜色
基本颜色
需要 xcolor 宏包:
\usepackage{xcolor}
\textcolor{red}{红色文本}
\textcolor{blue}{蓝色文本}
\textcolor{green}{绿色文本}
\textcolor{yellow}{黄色文本}
\textcolor{black}{黑色文本}
\textcolor{white}{白色文本}
\textcolor{gray}{灰色文本}
\textcolor{darkgray}{深灰色}
\textcolor{lightgray}{浅灰色}
\textcolor{brown}{棕色}
\textcolor{cyan}{青色}
\textcolor{magenta}{品红}
\textcolor{olive}{橄榄色}
\textcolor{orange}{橙色}
\textcolor{pink}{粉色}
\textcolor{purple}{紫色}
\textcolor{teal}{蓝绿色}
\textcolor{violet}{紫罗兰色}
自定义颜色
\definecolor{mycolor}{RGB}{255, 128, 0}
\textcolor{mycolor}{自定义颜色}
\definecolor{myblue}{HTML}{0066CC}
\textcolor{myblue}{HTML 颜色}
\definecolor{mygray}{gray}{0.5}
\textcolor{mygray}{灰度颜色}
背景色
\colorbox{yellow}{黄色背景}
\fcolorbox{red}{yellow}{红色边框,黄色背景}
段落格式
段落间距
\setlength{\parskip}{1em} % 段落间距
\setlength{\parindent}{2em} % 首行缩进
行距
\linespread{1.5} % 1.5 倍行距
\linespread{2.0} % 2 倍行距
\setlength{\baselineskip}{20pt} % 基线间距
段落对齐
\begin{flushleft}
左对齐段落
\end{flushleft}
\begin{flushright}
右对齐段落
\end{flushright}
\begin{center}
居中段落
\end{center}
段落命令
\noindent % 取消缩进
\indent % 强制缩进
\\ % 换行
\newline % 换行
\linebreak % 断行
\newpage % 新页
列表
无序列表
\begin{itemize}
\item 第一项
\item 第二项
\item 第三项
\end{itemize}
有序列表
\begin{enumerate}
\item 第一项
\item 第二项
\item 第三项
\end{enumerate}
描述列表
\begin{description}
\item[术语1] 术语1的解释
\item[术语2] 术语2的解释
\end{description}
嵌套列表
\begin{enumerate}
\item 第一项
\begin{itemize}
\item 子项1
\item 子项2
\end{itemize}
\item 第二项
\end{enumerate}
自定义列表样式
\usepackage{enumitem}
\begin{itemize}[label=$\star$]
\item 第一项
\item 第二项
\end{itemize}
\begin{enumerate}[label=\Roman*.]
\item 第一项
\item 第二项
\end{enumerate}
引用
短引用
\begin{quote}
这是一段短引用。
\end{quote}
长引用
\begin{quotation}
这是一段长引用。
可以包含多个段落。
\end{quotation}
诗歌
\begin{verse}
诗歌内容\\
第二行\\
第三行
\end{verse}
脚注
基本脚注
这是正文\footnote{这是脚注内容。}。
自定义脚注标记
\footnote[1]{自定义编号脚注}
\footnote*{星号脚注}
脚注格式
\renewcommand{\thefootnote}{\fnsymbol{footnote}} % 符号标记
\renewcommand{\thefootnote}{\alph{footnote}} % 字母标记
\renewcommand{\thefootnote}{\roman{footnote}} % 罗马数字
边注
\marginpar{这是边注}
\marginpar{\leftarrow 左侧边注}
\marginpar{右侧边注 \rightarrow}
删除线
需要 ulem 宏包:
\usepackage{ulem}
\sout{删除线}
\uline{下划线}
\uuline{双下划线}
\uwave{波浪线}
\xout{斜删除线}
\dashuline{虚线下划线}
\dotuline{点线下划线}
小结
本章介绍了 LaTeX 文本格式化:
- 字体样式:粗体、斜体、等宽等
- 字号:相对字号和绝对字号
- 颜色:基本颜色和自定义颜色
- 段落格式:段落间距、行距、对齐
- 列表:无序、有序、描述列表
- 引用:短引用、长引用、诗歌
- 脚注:基本脚注和自定义格式
- 边注和删除线
掌握文本格式化可以创建美观的文档。下一章将介绍数学公式。