数式の基本的な書き方
LaTeXで数式を書くには大きく「インライン数式」と「別行立て数式(ディスプレイスタイル数式)」の2つがあります。
インライン数式の場合には,$
で挟んだ部分が数式になります。
別行立て数式は$ax^2+bx+c=0$と書けます。
![](https://icochan1.net/wp-content/uploads/2023/08/image-6.png)
別行立て数式の場合にはequation
環境などを使います。
別行立て数式はequation環境などを使います。
\begin{equation}
ax^2+bx+c=0
\end{equation}
![](https://icochan1.net/wp-content/uploads/2023/08/image-7-1024x102.png)
数式の表示方法のカスタマイズ
数式を改行する
長い数式を改行したい場合にはmultline
環境を使います。
改行したい位置に\\
を入力します。
\begin{multline}
S = a_1 + a_2 + a_3 + a_4 + a_5 + a_6 + a_7 \\
+ b_1 + b_2 + b_3 + b_4 + b_5 + b_6 + b_7 \\
+ c_1 + c_2 + c_3 + c_4 + c_5 + c_6 + c_7
\end{multline}
![](https://icochan1.net/wp-content/uploads/2023/08/image-11-1024x121.png)
また,equation
環境とsplit
環境を組み合わせることで,位置合わせをすることもできます。
位置合わせをしたい場所に&
を入力することで位置が揃います。
\begin{equation}
\begin{split}
S &= a_1 + a_2 + a_3 + a_4 + a_5 + a_6 + a_7 \\
&+ b_1 + b_2 + b_3 + b_4 + b_5 + b_6 + b_7 \\
&+ c_1 + c_2 + c_3 + c_4 + c_5 + c_6 + c_7
\end{split}
\end{equation}
![](https://icochan1.net/wp-content/uploads/2023/08/image-40-1024x157.png)
数式番号を表示しない
LaTeXのequation
環境やalign
環境などの数式環境ではデフォルトで数式番号がつくようになっています。
それぞれの環境で数式番号の外し方は同様になっており,環境名の後ろに*
をつけます。
\begin{equation*}
ax^2+bx+c=0
\end{equation*}
\begin{equation}
ax^3+bx^2+cx+d=0
\end{equation}
![](https://icochan1.net/wp-content/uploads/2023/08/image-16-1024x169.png)
数式を左揃えにする
数式はデフォルトで中央揃えになるように設定されています。
数式を左揃えにするにはflalign
環境で&
を2つ使うことで出来ます。
左寄せにします。
\begin{flalign}
& ax^2+bx+c=0 &
\end{flalign}
![](https://icochan1.net/wp-content/uploads/2023/08/image-20-1024x98.png)
数式の塊を左寄せにしたい場合には,align
環境を使います。
\begin{align}
&ax^2+bx+c=0 \\
&ax^3+bx^2+cx+d=0
\end{align}
![](https://icochan1.net/wp-content/uploads/2023/08/image-30-1024x151.png)
複数の数式を縦に並べる
複数の数式を続けて書く
単純に数式を複数書きたい場合には,equation
環境を連続して書けば良いです。
\begin{equation}
ax^2+bx+c=0
\end{equation}
\begin{equation}
ax^3+bx^2+cx+d=0
\end{equation}
![](https://icochan1.net/wp-content/uploads/2023/08/image-9-1024x138.png)
数式の行間を狭くするにはgather
環境で一気に書くこともできます。
\begin{gather}
ax^2+bx+c=0 \\
ax^3+bx^2+cx+d=0
\end{gather}
![](https://icochan1.net/wp-content/uploads/2023/08/image-25-1024x144.png)
左端からの距離を明示的に指定したい場合には,fleqn
環境を使います。
\begin{fleqn}[5pt] ~ \end{fleqn}
と書くことで,左端から5ptの距離から数式が始まります。
\begin{fleqn}[5pt]
\begin{align}
&ax^2+bx+c=0 \\
&ax^3+bx^2+cx+d=0
\end{align}
\end{fleqn}
複数の数式をまとめて書く
連立方程式のように中括弧で囲まれた数式を書きたい場合には,alignedat
環境を使います。
\begin{equation}
\left\{
\begin{alignedat}{2}
x+y = 2 \\
2x+5y=10
\end{alignedat}
\right.
\end{equation}
![](https://icochan1.net/wp-content/uploads/2023/08/image-23-1024x136.png)
イコールの位置を揃えたい場合には&
を使います。
\begin{equation}
\left\{
\begin{alignedat}{2}
x + y &= 2 \\
2x + 5y &=10
\end{alignedat}
\right.
\end{equation}
![](https://icochan1.net/wp-content/uploads/2023/08/image-24-1024x136.png)
場合分けの関数を表示する
条件によって変わる関数を表現するにはcases
環境を組み合わせます。
\begin{equation}
f(x) =
\begin{cases}
x^2+5x+1 & (x \geqq 0) \\
0 & (x < 0)
\end{cases}
\end{equation}
![](https://icochan1.net/wp-content/uploads/2023/08/image-29-1024x142.png)
複数の数式を横に並べる
数式を横に並べる時には,数式同士の間に\quad
を入力します。
\begin{equation}
ax^2+bx+c=0, \quad ax^3+bx^2+cx+d=0
\end{equation}
![](https://icochan1.net/wp-content/uploads/2023/08/image-28-1024x100.png)
行列を書く
行列を表示する環境は5種類あります。
それぞれは括弧の付け方が異なります。
括弧なしの場合
matrix
環境を使います。要素の間には&
を挿入し,行の終わりには\\
を挿入します。
\begin{matrix}
a_{1,1} & a_{1,2} \\
a_{2,1} & a_{2,2}
\end{matrix}
![](https://icochan1.net/wp-content/uploads/2023/08/image-33.png)
小括弧をつける場合
pmatrix
環境を使います。要素の間には&
を挿入し,行の終わりには\\
を挿入します。
\begin{pmatrix}
a_{1,1} & a_{1,2} \\
a_{2,1} & a_{2,2}
\end{pmatrix}
![](https://icochan1.net/wp-content/uploads/2023/08/image-34.png)
大括弧をつける場合
bmatrix
環境を使います。要素の間には&
を挿入し,行の終わりには\\
を挿入します。
\begin{bmatrix}
a_{1,1} & a_{1,2} \\
a_{2,1} & a_{2,2}
\end{bmatrix}
![](https://icochan1.net/wp-content/uploads/2023/08/image-35.png)
中括弧をつける場合
Bmatrix
環境を使います。要素の間には&
を挿入し,行の終わりには\\
を挿入します。
\begin{Bmatrix}
a_{1,1} & a_{1,2} \\
a_{2,1} & a_{2,2}
\end{Bmatrix}
![](https://icochan1.net/wp-content/uploads/2023/08/image-36.png)
行列式にする場合
vmatrix
環境を使います。要素の間には&
を挿入し,行の終わりには\\
を挿入します。
\begin{vmatrix}
a_{1,1} & a_{1,2} \\
a_{2,1} & a_{2,2}
\end{vmatrix}
![](https://icochan1.net/wp-content/uploads/2023/08/image-37.png)
線を二重にする場合には,Vmatrix
環境を使います。
\begin{Vmatrix}
a_{1,1} & a_{1,2} \\
a_{2,1} & a_{2,2}
\end{Vmatrix}
![](https://icochan1.net/wp-content/uploads/2023/08/image-38.png)
行列の要素の位置を設定する
行列の要素はデフォルトで中央揃えとなっています。
左揃え,右揃えにする時には,それぞれ{環境名*}[l]
,{環境名*}[r]
とします。
\begin{vmatrix*}[l]
a_{1,1} & a_{1,2} \\
a_{2,1} & a_{2,2}
\end{vmatrix*}
行列に線を入れる場合
行列の任意の列に線を入れる場合には,表と同じく縦線は|
,横線は\hline
で指定します。
![](https://icochan1.net/wp-content/uploads/2023/04/a402c696bf493a873c765923653c07e6-300x169.png)
array
環境で表現することができます。
\left(
\begin{array}{cc|cc}
a_{11} & a_{12} & \dots & a_{1j} \\
a_{21} & a_{22} & \dots & a_{2j} \\ \hline
\vdots & \vdots & \ddots & \vdots \\
a_{i1} & a_{i2} & \dots & a_{ij}
\end{array}
\right)
![](https://icochan1.net/wp-content/uploads/2023/08/image-39.png)
コメント