LaTex语法

简介

基本框架

\documentclass{article}
\title{Your Paper}
\author{Your name}

\begin{document}

% \maketitle这个控制序列可以将这些信息按照预定的格式打印出来。%
\maketitle

\begin{abstract}
Your abstract.
\end{abstract}

\section{Introduction}
This is an instance.

\section{Some examples to get started}
\subsection{How to create Secttoions and Subsections}

\end{document}

基本语法

引入编码宏包

\usepackage[options]{package-name}

宏包分类

宏包名_1 说明
amsmath AMS 数学公式扩展
mathtools 数学公式扩展宏包,提供了公式编号定制和更多的符号、矩阵等
amsfonts AMS 扩展符号的基础字体支持
amssymb 在 amsfonts 基础上将 AMS 扩展符号定义成命令
bm 提供将数学符号加粗的命令 \bm
siunitx 以国际单位规范排版物理量的单位
mhchem 排版化学式和方程式。
tipa 排版国际音标
宏包名_2 说明
lmodern Latin Modern 字体,对 Computer Modern 字体的扩展
cmbright 仿 Computer Modern 风格的无衬线字体
euler Euler 风格数学字体,也出自于高德纳之手
ccfonts Concrete 风格字体
txfonts Times 风格的字体宏包
pxfonts Palatino 风格的字体宏包
stix Times 风格的字体宏包
newtxtext,newtxmath txfonts 的改进版本,分别设置文本和数学字体
newpxtext,newpxmath pxfonts 的改进版本,分别设置文本和数学字体
mathptmx psnfss 字体宏集之一, Times 风格,较为陈旧,不推荐使用
mathpazo psnfss 字体宏集之一, Palatino 风格,较为陈旧,不推荐使用
fourier fourier 风格数学字体,配合 Utopia 正文字体
fouriernc fourier 风格数学字体,配合 New Century Schoolbook 正文字体
arev Arev 无衬线字体宏包, Vera Sans 风格
mathdesign 配合 Charter / Garamond / Utopia 正文字体的数学字体宏包
宏包名_2 说明
cm-unicode Computer Modern 风格的 Unicode 字体,支持多种西方语言
dejavu DejaVu 开源字体
droid vDroid 开源字体
inconsolata Inconsolata 开源等宽字体
libertine Linux Libertine / Linux Biolium 开源字体
roboto Roboto 开源无衬线字体
sourcesanspro Source Sans Pro 开源无衬线字体
sourcecodepro Source Code Pro 开源等宽字体
宏包名_3 说明
mathabx 数学符号宏包之一
MnSymbol 数学符号宏包之一,配合 Minion Pro 文本字体
fdsymbol 数学符号宏包之一
pifont Zapf Dingbats 符号宏包
宏包名_4 说明
geometry 修改页面尺寸、页边距、页眉页脚等参数
fancyhdr 修改页眉页脚格式,令页眉页脚可以左对齐、居中、右对齐
titlesec 修改章节标题 \chapter、 \section 等的格式
titletoc 修改目录中各条目的格式
tocloft 类似 titletoc 的修改目录条目格式的宏包
tocbibind 支持将目录、参考文献、索引本身写入目录项
footmisc 修改脚注 \footnote 的格式
indentfirst 令章节标题后的第一段首行缩进
宏包名_5 说明
booktabs 排版三线表
array 对表格列格式的扩展
tabularx 提供 tabularx 环境排版定宽表格,支持自动计算宽度的 X 列格式
arydshln 支持排版虚线表格线
colortbl 支持修改表格的行、列、单元格的颜色
multirow 支持合并多行单元格
makecell 支持在单元格里排版多行内容(嵌套一个单列的小表格)
diagbox 排版斜线表头
longtable 提供排版跨页长表格的 longtable 环境
ltxtable 跨页长表格可使用 tabularx 的 X 列格式
tabu 提供排版复杂格式表格的 tabu 环境,与 longtable 一同调用时,提供排版复杂格式跨页长表格的 longtabu 环境
graphicx 支持插图
bmpsize latex + dvipdfmx 命令下支持 BMP/JPG/PNG 等格式的位图
epstopdf pdflatex 命令下支持 EPS 格式的矢量图
wrapfig 支持简单的文字在图片周围的绕排
subfig 提供子图表和子标题的排版。类似宏包有 subfigure 和 subcaption 等
caption 控制浮动体标题的格式
bicaption 生成双语浮动体标题
float 为浮动体提供不浮动的 H 模式;提供自定义浮动体结构的功能
宏包名_6 说明
ulem 提供排版可断行下划线的命令 \uline 以及其它装饰文字的命令
endnote 排版尾注
marginnote 改善的边注排版功能
multicol 提供将内容自由分栏的 multicols 环境
multitoc 生成多栏排版的目录
minitoc 为章节生成独立的小目录
glossaries 生成词汇表
verbatim 对原始的 verbatim 环境的改善。提供了命令 \verbatiminput 调用源文件
fancyvrb 提供了代码排版环境 Verbatim 以及对版式的自定义
listings 提供了排版关键字高亮的代码环境 lstlisting 以及对版式的自定义。类似宏包有minted
algorithmic 一个简单的实现算法排版的宏包。如果要生成浮动体的话,需要搭配 algorithm 宏包使用
algorithm2e 较为复杂的、可定制的算法排版宏包。类似宏包有 algorithmicx 等
ntheorem 定制定理环境。类似宏包包括 theorem、 thmtools、 amsthm 等
mdframed 排版可自动断页的带边框文字段落,提供边框样式的定制功能
tcolorbox 以 TikZ 为基础提供排版样式丰富的彩色盒子的功能

文档类型

\documentclass{article}
\documentclass{book}
\documentclass{letter}
...

添加注释

% This is a annotation %

添加标题、作者、日期等信息

\title{UseManual}
\author{User}
\date{November 2021}

%打印今天的日期
\date{\today}

目录

\tableofcontents
\section{}
%一号标题
\subsection
%二号标题
\subsubseciton

目录标题居中

\documentclass[openany]{book}
% 目录标题居中
\renewcommand{\contentsname}{\centerline{mulu}}

\begin{document}
\tableofcontents
\chapter{First}
\section{one}
\section{two}

\chapter{Second}
\section{thr}
\section{fur}
\end{document}

目录加上链接

\documentclass[openany]{book}
\usepackage{lipsum}
% 引入hyperref宏包
% 链接默认颜色为红色,修改linkcolor
\usepackage[colorlinks,linkcolor=black]{hyperref}

\begin{document}
\tableofcontents
\chapter{First}
\section{one} \lipsum[1]
\section{two} \lipsum[2]

\chapter{Second}
\section{thr} \lipsum[3]
\section{fur} \lipsum[4]
\end{document}

段落

 %{}中的内容加粗显示
\paragraph{XIDIAN UNIVERSITY}is a famous university.
\subparagraph{School of telecommunication engineering} is in the best

图片

\includegraphics[width=0.3\textwidth]{xxx.jpg}

参数表

表 7.1: includegraphics Options

参数名 作用
height 图形的高度(可为任何 TEX 度量单位)。
totalheight 图形的全部高度,可为任何 TEX 度量单位( 6/95 增加)。
width 图形的宽度(可为任何 TEX 度量单位)。
scale 图形的缩放因子,设定 scale=2 会使 插入的图形的大小为其自然大小的两倍。
angle 设定旋转的角度,以度为单位,顺时钟方向为正。
origin origin 指定图形绕那一点旋转,缺省 是图形的参考点(12/95 增加)。初始点有可能与 第 8.3节的 \rotatebox 命令中的一样。 比如 origin=c 将使图形绕它的中心旋转。
bb 设定 BoundingBox 的值。 bb=10 20 100 200 设定 BoundingBox 的左下角在 (10,20),右上角在 (100,200)。因为 \includegraphics 会自动从 EPS 文件中读入 BoundingBox 行 所给的值,所以一般不使用 bb 这个选项。但它在 EPS 文件 中的 BoundingBox 丢失或出错时还是很有用的。

表 7.2: includegraphics Cropping Options

参数名 作用
viewpoint 指定图形可以被看到的部分。如同 BoundingBox 一样, 这是一个由四个数字,左下角和右上角的坐标所确定的区域。 这里的坐标是相对于 BoundingBox 的左下角的(6/95 增加)。 例如,如果图形的 BoundingBox 的值是 50 50 410 302, viewpoint=50 50 122 122 将显示以图形的左下角为左下角的一英寸大小的区域。 而 viewpoint=338 230 410 302 则会显示以图形的 右上角为右上角的一英寸大小的区域。 必须使用 clip 选项(见表 7.3) 来阻止显示视图以外的图形部分 。
trim 指定图形可以被看到的部分的另一选项。所给出的四个数字 分别代表了从左、下、右、上被截去的值。正数代表从此方向 截去的大小,而负数则代表从此方向加上的大小。

表 7.3: includegraphics Boolean Options

参数名 作用
noclip (缺省选项)显示整个的图形,即使有些部分在视图之外。
clip 当使用 clip 时,将不显示图形在视图之外的部分。
draft 当使用 draft 选项时,将只显示图形的 BoundingBox 和文件名,这使得显示和打印文档的速度加快。如果使用 draft 宏包选项,\usepackage[draft]{graphicx} 会导致文档中的所有图形都被以草稿(draft)方式插入。
final (缺省选项,除非使用\usepackage[draft]{graphicx}) final 选项使得图形被显示,经常用来覆盖 \usepackage[draft]
keepaspectratio 在没有设定 keepaspectratio选项时, 给定图形的高度(全部高度)和宽度会导致图形被不对称缩 放来满足所设定的高和宽。在设定 keepaspectratio 选项后,给定图形的高度(全部高度)和宽度时,图形会 保持原有的宽高比例,尽可能使得图形满足所设定的高和宽, 但是图形不会超出其中任一个。

添加换行

\title{This is first line \\ This is second line}
\newline % 与\\相同

% 强制换行,与\newline的区别为\linebreak的当前行分散对齐。
\linebreak

% 分段。
\par

% 换多行 %
\title{This is first line \\\ \\\ \\ This is second line}

% 换行,并且与下一行的行间距为原来行间距+offset。
\\[offset]

换页

\clearpage
\newpage

overleaf 支持中文

  1. 使用 ctex 宏包
\usepackage[fontset=ubuntu]{ctex}
  1. 使用 xelatex 引擎编译

去掉默认日期

\date{}

首行缩进

\usepackage{indentfirst} % 引入宏包
\noindent Thirty-two
\indent\setlength{\parindent}{1em}During  % 首行缩进

文字居中

\centerline{\large{Homework 1}}

生成随机文本

\documentclass[openany]{book}
\usepackage{lipsum}

\begin{document}
\tableofcontents
\chapter{First}
\section{one} \lipsum[1]
\section{two} \lipsum[2]

\chapter{Second}
\section{thr} \lipsum[3]
\section{fur} \lipsum[4]
\end{document}

代码块

\usepackage{listings}

\begin{document}
\begin{lstlisting}
% 代码段
\end{lstlisting}
\end{document}

样式一

\lstset{
 columns=fixed,       
 numbers=left,                                        % 在左侧显示行号
 numberstyle=\tiny\color{gray},                       % 设定行号格式
 frame=none,                                          % 不显示背景边框
 backgroundcolor=\color[RGB]{245,245,244},            % 设定背景颜色
 keywordstyle=\color[RGB]{40,40,255},                 % 设定关键字颜色
 numberstyle=\footnotesize\color{darkgray},           
 commentstyle=\it\color[RGB]{0,96,96},                % 设置代码注释的格式
 stringstyle=\rmfamily\slshape\color[RGB]{128,0,0},   % 设置字符串格式
 showstringspaces=false,                              % 不显示字符串中的空格
 language=c++,                                        % 设置语言
}

样式二

`` \lstset{ %
language=Octave, % the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
numbers=left, % where to put the line-numbers
numberstyle=\tiny\color{gray}, % the style that is used for the line-numbers
stepnumber=2, % the step between two line-numbers. If it's 1, each line
% will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
frame=single, % adds a frame around the code
rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. commens (green here))
tabsize=2, % sets default tabsize to 2 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
title=\lstname, % show the filename of files included with \lstinputlisting;
% also try caption instead of title
keywordstyle=\color{blue}, % keyword style
commentstyle=\color{dkgreen}, % comment style
stringstyle=\color{mauve}, % string literal style
escapeinside={%}{)}, % if you want to add LaTeX within your code
morekeywords={*,...} % if you want to add more keywords to the set

posted @ 2021-11-10 09:08  πππ  阅读(29)  评论(0)    收藏  举报