一、LaTeX數學公式初步
1.代碼展示
%導言區
\documentclass{article}
\usepackage{ctex}
\usepackage{amsmath}
%正文區
\begin{document}
\section{簡介}
\LaTeX{} 將排版內容分爲文本模式和數學模式。文本模式用於普通文字的排版,數學模式用於數學公式排版。
\section{行內公式}
\subsection{美元符號}
交換律是 $a+b=b+a$,如 $1+2=2+1=3$。
\subsection{小括號}
交換律是 \(a+b=b+a\),如 \(1+2=2+1=3\)。%使用\引出了左右括號
\subsection{math環境}
交換律是 \begin{math}a+b=b+a\end{math},如\begin{math}1+2=2+1=3\end{math}
\section{上下標}
\subsection{上標}
$3x^2-x+2=0$
$3x^{20}-x+2=0$ %使用{}來進行分組從而實現相應的排版
$3x^{3x^{20}-x+2}-x+2=0$
\subsection{下標}%使用下劃線來實現
$a_0,a_1,a_2,...a_{100},a_{3x^{20}-x+2}$
\section{希臘字母}
$\alpha$
$\beta$
$\gamma$
$\epsilon$
$\pi$
$\omega$
$\Gamma$
$\Delta$
$\Theta$
$\Pi$
$\Omega$
$\alpha^2+\beta^2+\gamma=0$
\section{數學函數}
$\log$
$\sin$
$\cos$
$\arccos$
$\arcsin$
$\ln$
$\sin^2 x+\cos^2 x=1$
$y=\sin^{-1} x$
$y=log_2 x$
$\sqrt{2}$
$\sqrt{x^2+\sqrt{2}}$
$\sqrt[4]{x}$ %可選次數可用於規定開方次數
\section{分式}
大約是原體積的$3/4$.
大約是原體積的$\frac{3}{4}$ %/frac的第一個參數是分子,第二個參數是分母
$\frac{\sqrt{x-1}}{\frac{x}{x^2+x+1}}$
\section{行間公式}
\subsection{美元符號}
交換律是 $$a+b=b+a$$ 如 $$1+2=2+1=3$$。
\subsection{中括號}
交換律是
\[a+b=b+a\]
如
\[1+2=2+1=3\]。
\subsection{displaymath環境}
交換律是 \begin{displaymath}a+b=b+a\end{displaymath}
如
\begin{displaymath}1+2=2+1=3\end{displaymath}
\subsection{自動編號公式equation環境}
交換律公式見式\ref{eq:commutative}
\begin{equation}%equation用於對公式進行編號
a+=b+a \label{eq:commutative}
\end{equation}
\subsection{不編號公式equation*環境}
交換律公式見式\ref{eq:commutative2}
\begin{equation*}%equation用於對公式進行編號,需使用\usepackage{amsmath}
a+=b+a \label{eq:commutative2}
\end{equation*}
公式的編號和交叉引用也是自動實現的,大家在排版中,要習慣於採用自動化的方式處理諸如圖、表、公式的編號和交叉引用。
\end{document}
2.結果展示
二、LaTex數學模式中的矩陣
%導言區
\documentclass{ctexart}
\usepackage{amsmath}
\newcommand{\adots}{\mathinner{\mkern2mu%
\raisebox{0.1em}{.}\mkern2mu\raisebox{0.4em}{.}%
\mkern2mu\raisebox{0.7em}{.}\mkern1mu}}
%正文區
\begin{document}
%矩陣環境,用&分隔列,用\\分隔行
\[
\begin{matrix}
0 & 1\\
1 & 0
\end{matrix} \qquad
\begin{pmatrix} %用於加括號
0 & 1\\
1 & 0
\end{pmatrix} \qquad
\begin{bmatrix} %用於加中括號
0 & 1\\
1 & 0
\end{bmatrix} \qquad
\begin{Bmatrix} %用於加大括號
0 & 1\\
1 & 0
\end{Bmatrix} \qquad
\begin{vmatrix} %用於加單豎線
0 & 1\\
1 & 0
\end{vmatrix} \qquad
\begin{Vmatrix} %用於加雙豎線
0 & 1\\
1 & 0
\end{Vmatrix} \qquad
\]
%可以使用上下標
\[
A=\begin{pmatrix}
a_{11}^2 & a_{12}^2 &a_{13}^2\\
0 & a_{22} & a_{23}\\
0 & 0& a_{33}
\end{pmatrix}
\]
%常用省略號:$\dots$、\vdots、$\ddots$
\[
A=\begin{bmatrix}
a_{11} & \dots & a_{1n}\\
\adots & \ddots& \vdots\\
0 & & a_{nn}
\end{bmatrix}_{n \times n} %在數學命令中,可以\times來排版乘號
\]
%分塊矩陣
\[
\begin{pmatrix}
\begin{matrix}1&0 \\0&1\end{matrix}
& \text{\Large 0}\\
\text{\Large 0} & \begin{matrix}1&0 \\0&-1\end{matrix}
\end{pmatrix}
\]%\text{}用於在數學模式中臨時切換到文本模式
%三角矩陣
\[\begin{pmatrix}
a_{11} & a_{12} & \cdots &a_{1n}\\
& a_{22} & \cdots & a_{2n}\\
& & \ddots & \vdots\\
\multicolumn{2}{c}{\raisebox{1.3ex}[0pt]{\Huge 0}} %\multicolumn{cols}{pos}{text}可用於合併多列;\raisebox來調整高度
& &a_{nn}
\end{pmatrix}
\]
%跨列的省略號:\hdotsfor{<列數>}
\[
\begin{pmatrix}
1 & \frac{1}{2} & \dots & \frac{1}{n}\\
\hdotsfor{4}\\ %用於產生擴列省略號
m & \frac{m}{2} & \dots & \frac{m}{n}
\end{pmatrix}
\]
%行內小矩陣(smallmatrix)環境
複數 $z=(x,y)$也可用矩陣
\begin{math}
\left(%需手動加上左括號
\begin{smallmatrix}
x & -y \\ y & x
\end{smallmatrix}
\right)%需手動加上右括號
\end{math}來表示。
%array環境(類似表格環境tabular)
\[
\begin{array}{r|r}
\frac 12 & 0\\
\hline
0 & -\frac abc \\%\frac後不能字節跟隨字母會產生語法錯誤
\end{array}
\]
%array環境可以排版更爲複雜的矩陣
\[
% @{<內容>}--添加任意內容,不加表項計數
% 此處添加一個負值空白,表示左移-5pt的 距離
\begin{array}{c@{\hspace{-5pt}}l} %c指定第一列居中對齊,l指定最後一列居左對齊
%第一行第一列
\left(%產生矩陣左側的小括號定界符
\begin{array}{ccc|ccc}
a& \cdots & a & b & \cdots & b\\
& \ddots & \vdots & \vdots & \adots\\
& & a & b\\ \hline
& & & c & \cdots & c\\
& & & \vdots & & \vdots\\
\multicolumn{3}{c|}{\raisebox{2ex}[0pt]{\Huge 0}}
& c & \cdots & c
\end{array}
\right)%產生矩陣右側的小括號定界符
&
% 第一行第二列,右側的大括號標示符
\begin{array}{l}
%$\left.僅表示與\right\}配對,什麼都不輸出
\left.\rule{0mm}{7mm}\right\}p\\ %\rule命令指定大括號的尺寸
\\
\left.\rule{0mm}{7mm}\right\}q
\end{array}
\\[-5pt]
%第二行第一列
\begin{array}{cc}
\underbrace{\rule{17mm}{0mm}}_m& %\rule命令指定大括號的尺寸
\underbrace{\rule{17mm}{0mm}}_m
\end{array}
&%第二行第二列
\end{array}
\]
\end{document}
三、LaTeX中的多行數學公式
首先,應注意使用的包環境
\documentclass{ctexart}
\usepackage{amsmath}
\usepackage{amssymb}
- gather和gather*環境(可以使用\換行)
% 帶編號
\begin{gather}%gather環境可以實現多行公式的排版
a+b=b+a\\
ab ba
\end{gather}
% 不帶編號
\begin{gather*}%gather環境可以實現多行公式的排版
3+5=5+3=8\\
3 \times 5 =5 \times 3
\end{gather*}
結果:
2.在\前使用\notag阻止編號
\begin{gather}
a+b=b+a \notag\\
ab ba
\end{gather}
結果
3.align 和align*環境(用&進行對齊)
% 帶編號
\begin{align}
x &=t+\cos t +1 \\
y &=2\sin t
\end{align}
%不帶編號
\begin{align*}
x &=t+\cos t +1 & x &=t+\cos t +1 & x &=t+\cos t +1 \\
y &=2\sin t & x &=t+\cos t +1 & x &=t+\cos t +1
\end{align*}
4.split環境(對齊採用align環境的方式,編號在中間)
\begin{equation}%實現一個公示的多行排版
\begin{split}
\cos 2z &=\cos^2 x-\sin62 x\\
&=2\cos^2 x-1
\end{split}
\end{equation}
5.case環境 可實現分段函數的排版
%case環境 可實現分段函數的排版
% 每個公式使用&分隔爲兩部分,
% 通常表示值和後面的條件
\begin{equation}
D(x)=\begin{cases}
1,&\text{如果} x \in \mathbb{Q};\\ %\in用於輸出屬於符號,\mathbb{}命令用於輸出花體字符;\text用於在數學模式中臨時切換到文本模式
0,&\text{如果} x \in \mathbb{R}\setminus\mathbb{Q}
\end{cases}
\end{equation}
四、LaTeX中的參考文獻-BibTeX
五、LaTeX中的參考文獻-BibLaTeX
六、LaTeX中定義新命令和環境