> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-tw/shu-xue/04-matrices.md).

# 矩陣

## amsmath 矩陣環境

該 `amsmath` 套件提供用於以不同定界符排版矩陣的指令。當你載入 `\usepackage{amsmath}` 到你的前言區後，你就可以在數學環境中使用以下環境：

| 類型                 | LaTeX 標記                                              | 顯示為                                                 |
| ------------------ | ----------------------------------------------------- | --------------------------------------------------- |
| 普通                 | `\begin{matrix} 1 & 2 & 3\\ a & b & c \end{matrix}`   | $$\begin{matrix}1 & 2 & 3\a & b & c\end{matrix}$$   |
| <p>括號；<br>圓括號</p>  | `\begin{pmatrix} 1 & 2 & 3\\ a & b & c \end{pmatrix}` | $$\begin{pmatrix}1 & 2 & 3\a & b & c\end{pmatrix}$$ |
| <p>方括號；<br>中括號</p> | `\begin{bmatrix} 1 & 2 & 3\\ a & b & c \end{bmatrix}` | $$\begin{bmatrix}1 & 2 & 3\a & b & c\end{bmatrix}$$ |
| <p>大括號；<br>花括號</p> | `\begin{Bmatrix} 1 & 2 & 3\\ a & b & c \end{Bmatrix}` | $$\begin{Bmatrix}1 & 2 & 3\a & b & c\end{Bmatrix}$$ |
| 豎線                 | `\begin{vmatrix} 1 & 2 & 3\\ a & b & c \end{vmatrix}` | $$\begin{vmatrix}1 & 2 & 3\a & b & c\end{vmatrix}$$ |
| 雙豎線                | `\begin{Vmatrix} 1 & 2 & 3\\ a & b & c \end{Vmatrix}` | $$\begin{Vmatrix}1 & 2 & 3\a & b & c\end{Vmatrix}$$ |

如果你需要建立具有不同 [分隔符號](/latex/zh-tw/shu-xue/03-brackets-and-parentheses.md)，你可以手動將它們加到純 `matrix`時將其指定為「語言名稱」。例如：

| LaTeX 標記                                                                       | 顯示為                                                                        |
| ------------------------------------------------------------------------------ | -------------------------------------------------------------------------- |
| `\left\lceil \begin{matrix} 1 & 2 & 3\\ a & b & c \end{matrix} \right\rceil`   | $$\left\lceil\begin{matrix}1 & 2 & 3\a & b & c\end{matrix}\right\rceil$$   |
| `\left\langle \begin{matrix} 1 & 2 & 3\\ a & b & c \end{matrix} \right\rvert`  | $$\left\langle\begin{matrix}1 & 2 & 3\a & b & c\end{matrix}\right\rvert$$  |
| `\left\langle \begin{matrix} 1 & 2 & 3\\ a & b & c \end{matrix} \right\rangle` | $$\left\langle\begin{matrix}1 & 2 & 3\a & b & c\end{matrix}\right\rangle$$ |

## 行內矩陣

在排版行內數學時，通常的 `matrix` 上述環境可能看起來太大。改用 `smallmatrix` 在這種情況下會更合適，不過你需要自行提供自己的 [分隔符號](/latex/zh-tw/shu-xue/03-brackets-and-parentheses.md).

```latex
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\noindent 嘗試在此處排版一個行內矩陣：
 $\begin{pmatrix}
  a & b\\
  c & d
\end{pmatrix}$,
但它看起來太大了，所以我們試試
$\big(\begin{smallmatrix}
  a & b\\
  c & d
\end{smallmatrix}\big)$
。
\end{document}
```

[在 Overleaf 中開啟這個 `smallmatrix` 範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=amsmath+matrix+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnoindent+Trying+to+typeset+an+inline+matrix+here%3A%0A+%24%5Cbegin%7Bpmatrix%7D%0A++a+%26+b%5C%5C+%0A++c+%26+d%0A%5Cend%7Bpmatrix%7D%24%2C++%0Abut+it+looks+too+big%2C+so+let%27s+try+%0A%24%5Cbig%28%5Cbegin%7Bsmallmatrix%7D%0A++a+%26+b%5C%5C%0A++c+%26+d%0A%5Cend%7Bsmallmatrix%7D%5Cbig%29%24+%0Ainstead.%0A%5Cend%7Bdocument%7D)

下列圖片顯示了上述範例所產生的輸出：

![Amsmatrix.png](/files/86bb5d44dc38ad18c1a9cab450318ff4b7dee728)

該 `mathtools` 套件提供 `psmallmatrix`, `bsmallmatrix` 等等環境以方便使用。

## 延伸閱讀

* [數學表達式](/latex/zh-tw/shu-xue/01-mathematical-expressions.md)
* [中括號與小括號](/latex/zh-tw/shu-xue/03-brackets-and-parentheses.md)
* [使用 amsmath 對齊方程式](/latex/zh-tw/shu-xue/06-aligning-equations-with-amsmath.md)
* [數學模式中的顯示樣式](/latex/zh-tw/shu-xue/10-display-style-in-math-mode.md)
* [LaTeX2ε 不那麼簡短的入門介紹](http://www.ctan.org/tex-archive/info/lshort/)
* [amsmath 套件文件](http://texdoc.net/pkg/amsmath)
* [mathtools 套件說明文件](http://texdoc.net/pkg/mathtools)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-tw/shu-xue/04-matrices.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
