PR

【LaTeX】さまざまな行列のかき方一覧

LaTeX
記事内に広告が含まれています。

\LaTeX における行列の書き方を一覧で紹介します。

なお,amsmath パッケージの使用は仮定しています。ほとんどの場合,読み込んでいると思うので問題ないでしょう。

行列のコマンド一覧

全て数式モードの中で使用します。

基本的な行列のコマンド一覧

行列コマンド備考
\begin{array}{cc} a & b \\ c & d \end{array}\begin{array}{cc}
   a & b \\
   c & d
\end{array}
{cc}c
center(中央揃え)
を指す
他にも l (左揃え),
r (右揃え)がある
\begin{matrix} a & b \\ c & d \end{matrix}\begin{matrix}
   a & b \\
   c & d
\end{matrix}
\begin{pmatrix} a & b \\ c & d \end{pmatrix}\begin{pmatrix}
   a & b \\
   c & d
\end{pmatrix}
\begin{bmatrix} a & b \\ c & d \end{bmatrix}\begin{bmatrix}
   a & b \\
   c & d
\end{bmatrix}
\begin{Bmatrix} a & b \\ c & d \end{Bmatrix}\begin{Bmatrix}
   a & b \\
   c & d
\end{Bmatrix}
\begin{vmatrix} a & b \\ c & d \end{vmatrix}\begin{vmatrix}
   a & b \\
   c & d
\end{vmatrix}
行列式
\begin{Vmatrix} a & b \\ c & d \end{Vmatrix}\begin{Vmatrix}
   a & b \\
   c & d
\end{Vmatrix}
\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}\begin{smallmatrix}
   a & b \\
   c & d
\end{smallmatrix}
\bigl( \begin{smallmatrix} a & b \\ c & d \end{smallmatrix}\bigl)\bigl(
\begin{smallmatrix}
   a & b \\
   c & d
\end{smallmatrix}
\bigl)
文中で
使う
A^\topA^\top転置行列
A^\mathsf{T}A^\mathsf{T}転置行列
A^\intercalA^\intercal転置行列
A^\mathrm{T}A^\mathrm{T}転置行列
A^* A^*随伴行列(共役転置)
A^\dagger A^\dagger随伴行列(共役転置)
{}^t\! A{}^t\! A転置行列
\! によって間のスペース
をなくしている
|A||A|行列式
\lvert A \rvert\lvert A \rvert行列式
\det A\det A行列式

mathtools パッケージを用いたさらなる行列一覧

mathtools パッケージを用いることで,さらに多くの行列を出力することが可能です。

行列コマンド備考
\begin{pmatrix*}[l] a & -b \\ -c & d \end{pmatrix*}\begin{pmatrix*}[l]
   a & -b \\
   -c & d
\end{pmatrix}
左揃え (left)
\begin{pmatrix*}[c] a & -b \\ -c & d \end{pmatrix*}\begin{pmatrix*}[c]
   a & -b \\
   -c & d
\end{pmatrix}
中央揃え (center),デフォルト。
上の pmatrix と同じ意味
\begin{pmatrix*}[r] a & -b \\ -c & d \end{pmatrix*}\begin{pmatrix*}[r]
   a & -b \\
   –c & d
\end{pmatrix}
右揃え (right)

このように,行列の内部の整列位置を変えることができます。他も同様なので,コマンドのみ挙げましょう。col 部分は l (左揃え), c (中央揃え), r (右揃え) のいずれかが入ります。

\begin{matrix*}[col]  <contents> \end{matrix*}
\begin{pmatrix*}[col] <contents> \end{pmatrix*}
\begin{bmatrix*}[col] <contents> \end{bmatrix*}
\begin{Bmatrix*}[col] <contents> \end{Bmatrix*}
\begin{vmatrix*}[col] <contents> \end{vmatrix*}
\begin{Vmatrix*}[col] <contents> \end{Vmatrix*}

小さな行列も,さまざまなものを出力できます。

\begin{smallmatrix*}[col] <contents> \end{smallmatrix*}
\begin{psmallmatrix} <contents> \end{psmallmatrix}
\begin{psmallmatrix*}[col] <contents> \end{psmallmatrix*}
\begin{bsmallmatrix} <contents> \end{bsmallmatrix}
\begin{bsmallmatrix*}[col] <contents> \end{bsmallmatrix*}
\begin{Bsmallmatrix} <contents> \end{Bsmallmatrix}
\begin{Bsmallmatrix*}[col] <contents> \end{Bsmallmatrix*}
\begin{vsmallmatrix} <contents> \end{vsmallmatrix}
\begin{vsmallmatrix*}[col] <contents> \end{vsmallmatrix*}
\begin{Vsmallmatrix} <contents> \end{Vsmallmatrix}
\begin{Vsmallmatrix*}[col] <contents> \end{Vsmallmatrix*}

大きな行列の例・その他のコマンド一覧

大きな行列の入力方法を「行列自体」→「そのコマンド」の順に記します。必要なものをコピペして使ってください。

m×n行列

\begin{pmatrix} a_{11} & a_{12} & \dots & a_{1n} \\ a_{21} & a_{22} & \dots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \dots & a_{mn} \end{pmatrix}

\begin{pmatrix} 
  a_{11} & a_{12} & \dots  & a_{1n} \\
  a_{21} & a_{22} & \dots  & a_{2n} \\
  \vdots & \vdots & \ddots & \vdots \\
  a_{m1} & a_{m2} & \dots  & a_{mn}
\end{pmatrix}

m×n行列(i,j)強調バージョン

\begin{pmatrix} a_{11} & \dots & a_{1j} & \dots & a_{1n} \\ \vdots & & \vdots & & \vdots\\ a_{i1} & \dots & a_{ij} & \dots &a_{in} \\ \vdots & & \vdots & & \vdots \\ a_{m1} & \dots & a_{in} & \dots & a_{mn} \end{pmatrix}

\begin{pmatrix} 
  a_{11} & \dots & a_{1j} & \dots & a_{1n} \\
  \vdots &       & \vdots &       & \vdots \\
  a_{i1} & \dots & a_{ij} & \dots & a_{in} \\
  \vdots &       & \vdots &       & \vdots \\
  a_{m1} & \dots & a_{in} & \dots & a_{mn}
\end{pmatrix}

行列に線を入れる

\left( \begin{array}{c|ccc} a_{11} & a_{12} & \dots & a_{1n} \\ \hline a_{21} & a_{22} & \dots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \dots & a_{mn} \end{array} \right)

\left(
\begin{array}{c|ccc} 
  a_{11} & a_{12} & \dots  & a_{1n} \\ \hline
  a_{21} & a_{22} & \dots  & a_{2n} \\
  \vdots & \vdots & \ddots & \vdots \\
  a_{m1} & a_{m2} & \dots  & a_{mn}
\end{array} 
\right)

縦の線の位置をc|ccc で指定し,横の線の位置を \hline で指定しています。

行列に様々な線を入れる

\left(\begin{array}{c:c|c||c} a & b & c & d \\ \hdashline e & f & g & h \\ \hline i & j & k & l \\ \hline \hline m & n & o & p \end{array} \right)

\left(
\begin{array}{c:c|c||c}
   a & b & c & d \\ \hdashline
   e & f & g & h \\ \hline
   i & j & k & l \\ \hline \hline
   m & n & o & p
\end{array}
\right)

対角行列と大きな0

\begin{pmatrix} a_{11}\\ & a_{22} & & {\huge{0}}\\ & & \ddots\\ & \huge{0} & & \ddots\\ & & & & a_{nn} \end{pmatrix}

\begin{pmatrix}
  a_{11}                                                \\
         & a_{22}          &        & \text{\huge{0}}   \\
         &                 & \ddots                     \\
         & \text{\huge{0}} &        & \ddots            \\
         &                 &        &           & a_{nn}
\end{pmatrix}

対角行列の定義は対角行列の定義と基本的な性質6つを確認してください。

上三角行列・下三角行列

\begin{pmatrix} a_{11} & a_{12} & \dots & a_{1n} \\ & a_{22} &\dots & a_{2n} \\ &&\ddots & \vdots \\ \huge{0}&&&a_{nn} \end{pmatrix}

\begin{pmatrix}
  a_{11}          & a_{12} & \dots  & a_{1n} \\
                  & a_{22} & \dots  & a_{2n} \\
                  &        & \ddots & \vdots \\
  \text{\huge{0}} &        &        & a_{nn}
\end{pmatrix}

\begin{pmatrix} a_{11} &&& \huge{0}\\ a_{21} & a_{22} \\ \vdots& & \ddots \\ a_{n1} & a_{n2} & \dots & a_{nn} \end{pmatrix}

\begin{pmatrix}
  a_{11} &        &        & \text{\huge{0}} \\
  a_{21} & a_{22}                            \\
  \vdots &        & \ddots                   \\
  a_{n1} & a_{n2} & \dots  & a_{nn} 
\end{pmatrix}[/katex]

上三角行列・下三角行列の定義は上三角行列・下三角行列の定義と性質6つを確認してください。

基本行列

\begin{pmatrix} 1 &&&&& \\ & \ddots&&& & \\ && 1 &\dots & c & & \\ &&&\ddots&\vdots&&\\ & & & & 1 & & \\ &&&&& \ddots \\ &&&&&& 1 \end{pmatrix}
\begin{pmatrix}
  1                                            \\
    & \ddots                                   \\
    &        & 1 & \dots & c                   \\
    &        &   & \ddots& \vdots              \\
    &        &   &       & 1                   \\
    &        &   &       &        & \ddots     \\
    &        &   &       &        &        & 1 
\end{pmatrix}
\begin{pmatrix} 1 &&&&& \\ & \ddots&&& & \\ && 0 &\dots & 1 & & \\ &&\vdots&&\vdots&&\\ & & 1& \dots& 0 & & \\ &&&&& \ddots \\ &&&&&& 1 \end{pmatrix}
\begin{pmatrix}
  1                                                \\
    & \ddots                                       \\
    &        & 0      & \dots & 1                  \\
    &        & \vdots &       & \vdots             \\
    &        & 1      & \dots & 0                  \\
    &        &        &       &       & \ddots     \\
    &        &        &       &       &        & 1
\end{pmatrix}
\begin{pmatrix} 1 &&&&& \\ & \ddots&&& & \\ && c& && & \\ &&&\ddots&&\\ & & & & \ddots& \\ &&&&& \ddots \\ &&&&&& 1 \end{pmatrix}
\begin{pmatrix}
  1                                           \\
    & \ddots                                  \\
    &        & c &                            \\
    &        &   & \ddots                     \\
    &        &   &      & \ddots              \\
    &        &   &      &        & \ddots     \\
    &        &   &      &        &        & 1 
\end{pmatrix}

基本行列の定義は,行列の基本変形についてわかりやすく図解するを参照してください。

成分をまたいだ点々

hdotsfor を用いた行列の書き方の例
\begin{pmatrix}
  a_{11} & \dots & a_{1n} \\
  \hdotsfor{3} \\
  a_{m1} & \dots & a_{mn} 
\end{pmatrix}

\hdotsfor{n} n 行分の横ドットを出力します。また,\hdotsfor[m]{n} とすればドット間隔を m 倍に広げることができます。以下,その例です。

hdotsfor を用いた行列の書き方の例
\begin{pmatrix}
  a_{11} & \dots & a_{1n} \\
  \hdotsfor[2]{3} \\
  a_{m1} & \dots & a_{mn} 
\end{pmatrix}

ファンデルモンドの行列式

\begin{vmatrix} 1 & x_1 & x_1^2 & \dots &x_1^{n-1} \\ 1 & x_2 & x_2^2 & \dots & x_2^{n-1} \\ \vdots & \vdots & \vdots & \cdots & \vdots \\ 1 & x_n & x_n^2 & \dots & x_n^{n-1} \end{vmatrix}
\begin{vmatrix}
  1       & x_1    & x_1^2  & \dots  & x_1^{n-1} \\
  1       & x_2    & x_2^2  & \dots  & x_2^{n-1} \\
  \vdots  & \vdots & \vdots & \cdots & \vdots    \\
  1       & x_n    & x_n^2  & \dots  & x_n^{n-1}
\end{vmatrix}
\begin{vmatrix} 1 & 1 & \dots &1\\ x_1 & x_2 & \dots & x_n \\ x_1^2 & x_2^2 & \dots & x_n^2 \\ \vdots & \vdots & \cdots & \vdots \\ x_1^{n-1} & x_2^{n-1} & \dots & x_n^{n-1} \end{vmatrix}
\begin{vmatrix}
  1         & 1         & \dots  & 1         \\
  x_1       & x_2       & \dots  & x_n       \\
  x_1^2     & x_2^2     & \dots  & x_n^2     \\
  \vdots    & \vdots    & \cdots & \vdots    \\
  x_1^{n-1} & x_2^{n-1} & \dots  & x_n^{n-1}
\end{vmatrix}

ファンデルモンドの行列式について詳しくはファンデルモンドの行列式とその証明2つを参照してください。

Physicsパッケージを用いた行列の書き方

Physics パッケージを用いると,さまざまな行列が更に簡単に書けるようになります。

行列コマンド備考
\begin{matrix} a & b \\ c & d \end{matrix}\mqty{a & b \\ c & d}matrixquantity
の略
\smqty{}
とすると小サイズになる
\begin{pmatrix} a & b \\ c & d \end{pmatrix}\mqty(a & b \\ c & d)
\pmqty{a & b \\ c & d}
\smpty(), \spmqty{}
とすると小サイズになる
phisics パッケージの alternate parentheses による行列の画像\mqty*(a & b \\ c & d)
\Pmqty{a & b \\ c & d}
\smqty*(), \sPmqty{}
とすると小サイズになる
\begin{bmatrix} a & b \\ c & d \end{bmatrix}\mqty[a & b \\ c & d]
\bmqty{a & b \\ c & d}
\smqty[], \sbmqty{}
とすると小サイズになる
\begin{vmatrix} a & b \\ c & d \end{vmatrix}\mqty|a & b \\ c & d|
\vmqty{a & b \\ c & d}
\mdet{a & b \\ c & d}
\smqty||, \svmqty{}, \smdet{}
とすると小サイズになる
\begin{matrix} 1 & 0 & 0\\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{matrix}\imat{3}identity matrix
単位行列
\mqty(\imat{3})
のように上と組み合わせて

使うとよい(以下そうする)。
\begin{pmatrix} 1 & 0 & 0\\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix}\mqty(\imat{3})
\begin{pmatrix} 0 & 0 & 0\\ 0 & 0 & 0 \end{pmatrix}\mqty(\zmat{2}{3})zero matrix
零行列
\begin{pmatrix} 1 & 1 & 1\\ 1 & 1 & 1 \end{pmatrix}\mqty(\xmat{1}{2}{3})
\begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \\ a_{31} & a_{32} \end{pmatrix}\mqty(\xmat*{a}{3}{2})
\begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\mpty(\pmat{0})パウリ行列(単位行列) \sigma_0
\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\mqty(\pmat{1})パウリ行列 \sigma_1
\begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}\mqty(\pmat{2})パウリ行列 \sigma_2
\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\mqty(\pmat{3})パウリ行列 \sigma_3
\begin{pmatrix} 1 && \\ & 2 & \\ & & 3 \end{pmatrix}\mqty(\dmat{1,2,3})diagonal matrix
対角行列
\begin{pmatrix} 1 & 0 & 0\\ 0 & 2 & 0 \\ 0 & 0 & 3 \end{pmatrix}\mqty(\dmat[0]{1,2,3})diagonal matrix
対角行列
\begin{pmatrix} 1 && \\ & 2 & 3 \\ & 4 & 5 \end{pmatrix}\mqty(\dmat{1, 2&3\\4&5})カンマ毎に行列を入れてもよい
\begin{pmatrix} & &1 \\ & 2 & \\ 3 & & \end{pmatrix}\mqty(\admat{1,2,3})anti-diagonal matrix
反対角行列
\begin{pmatrix} 0 & 0 & 1\\ 0 & 2 & 0 \\ 3 & 0 & 0 \end{pmatrix}\mqty(admat[0]{1,2,3})anti-diagonal matrix
反対角行列
\begin{pmatrix} & & 1\\ 2 & 3 & \\ 4 & 5 & \end{pmatrix}\mqty(\admat{1, 2&3\\4&5})カンマ毎に行列を入れてもよい

便利ですね。

その他の行列のコマンド

その他 rank など,定義されていないコマンドもあります。これは,\DeclareMathOperator を用いて自分で定義するとよいです。プリアンブルに例えば以下のように書きます。

\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\Tr}{Tr}
\DeclareMathOperator{\Det}{Det}
\DeclareMathOperator{\Log}{Log}
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\rk}{rk}
\DeclareMathOperator{\diag}{diag}
\DeclareMathOperator{\corank}{corank}
\DeclareMathOperator{\Ker}{Ker}
\DeclareMathOperator{\coker}{coker}
\DeclareMathOperator{\Coker}{Coker}

こうすることで,\rank などとすれば,そのコマンドが使えるようになります。

他のLaTeXコマンドまとめ記事

参考

  1. 奥村晴彦, 黒木裕介「LaTeX 美文書作成入門」(技術評論社, 第9版, 2023)
  2. amsmath – AMS mathematical facilities for LATEX
  3. mathtools – Mathematical tools to use with amsmath
  4. physics – Macros supporting the Mathematics of Physics