
如何使用 數學模式
工具
推薦一些工具能快速上手
- Overleaf:免安裝線上編輯器,也有各式現成模板可以直接使用。
- Overleaf 教學網站:語法使用教學。
- Codecogs:數學方程式編輯器,提供可視化的介面,是不記得數學指令的新手福音。
- Table Generator:在裡面打表格是一個相對麻煩的事情,有這個工具能快速幫你實現。
- List of LaTeX mathematical symbols:符號表。
建議設定
\documentclass{article}
% Aligning equations
\usepackage{amsmath}
\allowdisplaybreaks % 允許align煥頁
% Math fonts
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{mathrsfs}
\begin{document}
Recommended settings
\end{document}
latex
接下來我們的內容會聚焦在數學模式,若無特別提及,則是指在\begin{document} … \end{document}
裡操作
數學模式
數學模式分為2種,一種是「內文數學模式(Inline math mode)」,另一種是「展示數學模式(Display math mode)」。
差別在於內文數學模式會嘗試將數學符號縮小至與一般內文等高,否則會導致行高變化太多不好看
內文模式
行高相同 test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test
展示模式
行高不同 test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test
在內文模式中,我們會使用一個錢字符將內文包起來$ ... $
,例如
$ f (x) = \sum_{i = 1}^{n} i^k $
latex
在展示模式中,我們會用兩個錢字符將內文包起來$$ ... $$
,或者\begin{環境名稱} ... \end{環境名稱}
,例如
$$ f (x) = \sum_{i = 1}^{n} i^k $$
\begin{align}
f (x) = \sum_{i = 1}^{n} i^k
\end{align}
latex
字體
一般來說內文會使用正體,數學模式內的符號會用斜體,例如f(x) = ax + b與的對比。而有公認定義的函數會用正體,例如。
我們有時候會需要在數學模式內輸入非數學符號,會希望用正體表示,可以用\text{…}
,例如
$$ f (x) > 0 \quad \text{for} \quad x > 0 $$
latex
常用數學
接下來的操作,請直接放在$...$
或$$ … $$
裡面。建議網站:Codecogs
操作
\pm \mp \times \dot \div | |
\cup \cap | |
\geq \leq \subset \supset \subseteq \supseteq |
分數 frace
語法;\frac{分子}{分母}
根號 sqrt
語法:\sqrt{n}
或\sqrt[m]{n}
也能與其他符號結合,例如分數\sqrt{\frac{a}{b}}
次方 ^
語法:a^b
或 {a}^{b}
,例e^{-\frac{1}{2}}
注意:次方符號預設只會將「下一個字元」放到次方位置上,例如123的456次方,要用{123}^{456}
而非123^456
。
大型符號
語法:\sum
\prod
\int
\bigcup
\bigcap
\lim
上下標:\sum_{i = 1}^{n}
\int_{a}^{b}
\lim_{n \to \infty}
非英文符號
\alpha \beta \gamma \delta | |
---|---|
\Gamma \Delta |
更多符號參考至LaTeX 符號表
大型括號
若想對大型符號做括號,例如分數的括號( \frac{a}{b} )
,會發現括號太小
語法:在括號左右兩側加上\left
和\right
,括號就會跟著內容自動設定大小,例如
\left| ... \right|
\left( ... \right)
\left[ ... \right]
\left\lbrace ... \right \rbrace
,由於大括號在有重要功能,因此語法稍有不同
單邊括號
若想達成單邊括號,例如
語法:將不需要的那側,換成\left.
或\right.
,例如\left. ... \right)
這項功能若組合則下標\left. \frac{ax}{b} \right|_{x = 0}
,則能做到微積分常使用的符號
多行操作 align
在展示數學模式中,若想達成多行對齊
可以使用align
或align*
環境,差別在有align*
無編號,而align
有
語法:以&
作為對齊點
\begin{align}
(a + b)^2 - b^2 & = (a^2 + 2ab + b^2) - b^2 \\
& = a^2 + 2 ab \\
& = a (a + 2b)
\end{align}
latex
陣列 array
想要達成陣列或多行算式,都能用array
環境做到
語法:以&
作為對齊點。其中有個參數{cc}
,c
代表「置中」、l
表示「置左」、r
表示「置右」。而第一個c
表示第一行;第二個c
表示第二行,以此類推。
$$ \begin{array}{cc}
a & b \\
c & d
\end{array} $$
latex
若想做到「第一行置左,第二行置中,第三行置右」,則可以
$$ \begin{array}{lcr}
1 & 23 & 456 \\
78910 & 11121 & 14151617
\end{array} $$
latex
矩陣
加上水平逗點\cdots
、垂直逗點\vdots
與斜線逗點\ddots
可以寫出下列陣列
$$ \begin{array}{cccc}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nn}
\end{array} $$
latex
最後在左右兩側加上大括號,就能寫出線性代數常用的矩陣形式
$$ \left( \begin{array}{cccc}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nn}
\end{array} \right) $$
latex
多行函數
以絕對值函數為例
$$ \begin{array}{lll}
x & \text{if} & x \geq 0 \\
-x & \text{if} & x < 0
\end{array} $$
latex
再加上一個單側大括號\left\lbrace ... \right.
$$ |x| =
\left\lbrace \begin{array}{lll}
x & \text{if} & x \geq 0 \\
-x & \text{if} & x < 0
\end{array} \right. $$
latex
Amsmath Package
介紹一個常用且好用的包,在設定區引入amsmath
\usepackage{amsmath}
latex
矩陣 matrix
在amsmath
的矩陣,內容預設置中,且只要微幅修改就能改變外圈括號的類型,例如pmatrix
\begin{pmatrix}
a & b \\
c & d \\
\end{pmatrix}
latex
另外還有數種類型的括號可以選,只要將pmatrix
換成下列任一項
pmatrix
bmatrix
Bmatrix
vmatrix
Vmatrix
多行 cases
再以絕對值為範例,用cases
就能快速的打出來
|x| =
\begin{cases}
x & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end{cases}
latex