LaTex入门——基本操作
- 相关知识均来源于overleaf的官方tutorial
- 学习时参照如何从零开始,入门 LaTeX?中“浮生六记”用户的回答
使用xeCJK宏包的简单LaTex文档
\documentclass{article}
\usepackage{xeCJK}
\usepackage{amsmath}
\begin{document}
$y = c_2 x^2 + c_1 x + c_0$
$F_n = F_{n-1} + F_{n-2}$
$\mu = A e^{Q/RT}$
$\Omega = \sum_{k=1}^{n} \omega_k$
\begin{equation}
\alpha + \beta + 1
\end{equation}
The roots of a quadratic equation are given by
\begin{equation*}%表达式不想编号就用equation*
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\end{equation*}
where $a$, $b$, and $c$ are \ldots
\begin{itemize}%无序列表
\item[-]符号自定义
\item[什么]都可以
\end{itemize}
\begin{enumerate}%有序列表
\item 没有太大自由
\item 但也有选项
\end{enumerate}
%若需将方程式沿=对齐,可使用&分开左栏(同一行里=前)和右栏(=后),使用双反斜线\\换行
\begin{align*}
(x+1)^3 &= (x+1)(x+1)(x+1)\\
&=(x+1)(x^2+2x+1)\\
&=x^3+3x^2+3x+1
\end{align*}
\end{document}
基本文本格式:
- 工作模式:使用纯文本plain text写代码,使用命令控制排版
- 使用xeCJK宏包则必须用XeTex/XeLaTex编译
- 所有命令都由反斜线\开始
- 所有文档开头都是\documentclass命令
- 放在花括号里 { } 的命令参数告诉latex文档的类型:article(普通文章)
- 将全文放在\begin{document} 和 \end{document}之间
数学排版:
- 易错点
- 英文引号:左上角的 ` 键表示左引号,单引号'表示右引号;两个`表示左双引号,两个单引号'表示右双引号
- latex中的保留符号:% # & $(在前面加上反斜线\以强制转换)
- 注释使用%标明
- $用来标识文本中的公式,$符号必须成对出现,具体使用见上图所示
- 如果公式繁杂,就用 \begin{equation} 和 \end{equation} 将它单行显示
- 注意:latex会忽略大多数空格,但equation模式中不能有空行,不能像分段那样连换两行
- 使用宏包时需要在头文件里用 \usepackage命令加载
运行结果如下所示