鉴于本人latex经验几乎为0,虽然可以利用AI来编辑.tex文本,但是觉得这样还是太浅显了,还是能看懂为好。

安装与配置可以见上一篇

Latex源文件的基本结构

%:注释

$$:公式块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
% 导言区
\documentclass{article}
%book,report,letter
\title{标题}
\author{作者}
\date{\today}

% 正文区
\begin{document}
\maketitle
内容...
Let$f(x)$ be defined by the formula
%中间空一行就是换行
$f(x)=3x^2+x-1$
$$f(x)=3x^2+x-1$$which is a polynomial of degree 2
\end{document}

image-20261003212003227

Latex中文处理

这个上一篇博客里面有具体写配置问题。

保证编码为UTF-8,写中文时还可以指定字体

1
2
3
4
5
6
7
%导言区
\documentclass{article}
\usepackage{ctex}
%需要ctex这个包

%如果需要命令定义的话
newcommand\...{}

image-20261003212747015

在终端中输入texdoc ctex,可以查看ctex包的具体信息

Latex字体字号设置

字体属性

字体族

罗马字体、无衬线字体、打字机字体

1
2
3
4
5
6
7
8
9
%罗马体
\textrm{}
%无衬线字体
\textsf{}
%打字机字体
\texttt{}
%可以字体声明
\rmfamily Roman Family
%可以加大括号圈定范围字体范围

字体系列

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
%字体形状(直立、斜体、伪斜体、小型大写 )
\textmd{Upright Shape}
\textit{Italic Shape}
\textsl{Slanted Shape}
\textsc{Small Caps Shape}

{\upshape ...}
{\itshape ...}
{\slshape ...}
{\scsshape ...}

%中文字体
{\songti 宋体}
{\heiti 黑体}
{\fangsong 仿宋}
{\kaishu 楷书}
%注意:中文记得引用ctex包

%字体大小
{\tiny }\\
{\scriptsize }

%中文字号设置命令
\zihao{-0} 你好!

Latex文档的基本结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
%导言区
\ctexset{
section={}
}
%正文区
\begin{document}
\tableofcontents
%整个文档的目录
\section{引言}
%插入正文 \par可以开启新段落
\section{实验方法}
\section{实验结果}
\subsection{数据}
\subsection{图标}
\subsubsection{实验条件}
\section{结论}
\section{致谢}

\end{document}

Latex中的特殊字符

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 \section{空白符号}
%空行分段,多个空行等于一个
%自动缩进,绝对不能用空格代替
%英文中多个空格处理(1个空格),中文中空格将被忽略
%汉字与其他字符间距会自动处理

%1em
a\quad b
%2em
a\qquad b
%0.5em
a\enspace b
%空格
a\ b
%硬空格
a~b

Latx中的插图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
%导言区
\usepackage{graphicx}
%语法:
\includegraphics[<选项>]{<文件名>}
%图片在当前目录下的figures目录
\graphicspath{{figures/}}
%格式:EPS,PDF,PNG,JPEG,BMP


%正文区
\begin{document}
\LaTeX{}中的插图
\includegraphics{<文件名>}
%如果大小不合适也可以进行修改
\includegraphics[]{}
\end{document}

Latex中的表格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
%正文区
\begin{document}
%列格式说明,空格不起作用
%l为左对齐,c为居中,r为右对齐
\begin{tabular}{l c c c r}
%中间可以加|隔开
\begin{tabular}{l|c|c|c|r}
%可以用\hline产生横线
\begin{tabular}{l|c|c|c|r}
\hline
姓名&语文&数学&外语&备注\\
\hline
%还有一个可以用p{<宽>}--本列固定宽度,能够自动换行
\begin{tabular}{l|c|c|c|p{1.5cm}|}
\end{tabular}
\end{document}

image-20261007222402910

当然还有很多的线条可以去添加

texdoc booktab

texdoc longtab

具体需要可查阅宏包

Latex中的浮动体

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
%正文区
\begin{document}
\LaTeX{}中的插图
\begin{figure}[]
\includegraphics[]{}
%对插图进行命名
\caption{}
\end{figure}
\LaTeX{}中的表格
\begin{table}
\begin{tabular}{l|c|c|c|r}
\hline
姓名&语文&数学&外语&备注\\
\hline
\end{tabular}
\end{table}
\end{document}

Latex数学公式初步

这个和markdown语法很像,有基础就方便多了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
\section{行内公式}
\subsection{美元符号}
$a+b=b+a$
\subsection{小括号}
\(a+b=b+a\)
\subsection{math环境}
\begin{math}
a+b=b+a
\end{math}
\section{上下标}
\subsection{上标}
$^$
\subsection{下标}
$_$

Latex数学公式矩阵

Latex数学公式的多行公式

Latex中的参考文献BibTex

Latex中参考文献BibLatex

Latex中的自定义命令和环境