# array

Used for custom mathematical arrays, matrices, and piecewise-style layouts where the author supplies an explicit column preamble.

https://texform.dev/latex/environments/array

## Metadata

| Field | Value |
| --- | --- |
| Topic | [Matrices](https://texform.dev/latex/topics/matrices) |
| Packages | base |
| Allowed mode | math |
| Tags | math-alignment, nestable |
| Commonality | high |
| Body mode | math |

## Syntax

### base

Argument specification: `o m:C`

Used for custom mathematical arrays, matrices, and piecewise-style layouts where the author supplies an explicit column preamble.

## Common tasks

### How to write a custom-column array

```latex
\begin{array}{cc} a & b \\ c & d \end{array}
```

[Open in Playground](https://play.texform.dev/?input=%5Cbegin%7Barray%7D%7Bcc%7D+a+%26+b+%5C%5C+c+%26+d+%5Cend%7Barray%7D)

### How to add a vertical rule in an array

```latex
\begin{array}{c|c} a & b \\ \hline c & d \end{array}
```

[Open in Playground](https://play.texform.dev/?input=%5Cbegin%7Barray%7D%7Bc%7Cc%7D+a+%26+b+%5C%5C+%5Chline+c+%26+d+%5Cend%7Barray%7D)

### How to right-align numeric columns

The preamble uses the same l/c/r letters as tabular.

```latex
\begin{array}{rcr} 12 & + & 3 \\ 4 & + & 56 \end{array}
```

[Open in Playground](https://play.texform.dev/?input=%5Cbegin%7Barray%7D%7Brcr%7D+12+%26+%2B+%26+3+%5C%5C+4+%26+%2B+%26+56+%5Cend%7Barray%7D)

## Examples

```latex
\begin{array}{cc} a & b \end{array}
```

[Open in Playground](https://play.texform.dev/?input=%5Cbegin%7Barray%7D%7Bcc%7D+a+%26+b+%5Cend%7Barray%7D)

```latex
\begin{array}[t]{cc} a & b \end{array}
```

[Open in Playground](https://play.texform.dev/?input=%5Cbegin%7Barray%7D%5Bt%5D%7Bcc%7D+a+%26+b+%5Cend%7Barray%7D)

## Renderer support

| Package | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- |
| base | full | partial | partial |

## Usage frequency

3.24% of formulas in the measured corpus contain this entry, rank 6 of 31 entries with frequency data.

## In TeXForm

TeXForm reads the environment body in math mode.

## See also

- [darray](https://texform.dev/latex/environments/darray)

## Test cases

### base

| Input | Case | MathJax | KaTeX | XeTeX |
| --- | --- | --- | --- | --- |
| \begin{array}{cc} a & b \end{array} | Positive: baseline | Pass | Pass | Pass |
| \begin{array}[a]{cc} a & b \end{array} | Positive: vary:o[0] | Pass | Fail | Pass |
| \begin{array}cc a & b \end{array} | Positive: bare[1] | Pass | Pass | Fail |
