Building an Array in Latex

  • Expression for an array begins with the following two commands,
    \begin{array}{justification}
    \end{array}
  • All the elements of the array will be placed between the above two commands.
  • Array elements can be justified according to your requirement with the use of justification command. l for left, c for centered or r for right justification.
  • The parameters passed through the justification command must match with the number of columns.
  • Separate the column by an &.
  • Seperate the row by a \\.

Look at the table below for examples on building arrays in Latex:

Array Latex Expression Comment

    \[\begin{array}{r} a \\ b \\ c \end{array}\]

$$
\begin{array}{r}
a \\
b \\
c
\end{array}
 $$
Plain array

    \[( \begin{array}{r} a \\ b \\ c \end{array} )\]

$$(
\begin{array}{r}
a \\
b \\
c
\end{array}
)
$$
Size of the parenthesis, not enough to enclose all the elements of the array

    \[\left( \begin{array}{r} a \\ b \\ c \end{array} \right)\]

$$\left(
\begin{array}{r}
a \\
b \\
c
\end{array}
\right)
 $$
Parenthesized array

    \[\left[ \begin{array}{rc} a&d \\ b&e \\ c&f \end{array} \right]\]

$$\left[
\begin{array}{rc}
a&d \\
b&e \\
c&f
\end{array}
\right]
$$
Note the change in braces[]

    \[\begin{array}{|r|c|l|} a&d&g \\ b&e&h \\ c&f&i \end{array}\]

$$
\begin{array}{|r|c|l|}
a&d&g \\
b&e&h \\
c&f&i
\end{array}
$$
To place vertical bars between the columns

    \[\left( \begin{array}{rcl} a&d&g \\ \hline b&e&h \\ \hline c&f&i \end{array} \right)\]

$$\left(
\begin{array}{|r|c|l|}
a&d&g \\
\hline
b&e&h \\
\hline
c&f&i
\end{array}
\right)
$$
Use the command \hline, to place horizontal bars between the rows

    \[\begin{array}{lcl} z & = & x \\ z & = & x+y \\ z & = & x+y+1 \end{array}\]

$$
\begin{array}{lcl}
z & = & x \\
z & = & x+1 \\
z & = & x+y+2
\end{array}
$$
Using array environment to align equations

    \[\left( \begin{array}{rcl} aaa&ddd&ggg \\ bb&ee&hh \\ c&f&i \end{array} \right)\]

$$\left(
\begin{array}{rcl}
aaa&ddd&ggg \\
bb&ee&hh \\
c&f&i
\end{array}
\right)
$$
To clarify the role of justification in the expression. Here, it is {rcl}-1st is right, 2nd is centre and the last is left justified.

Leave a Reply