Create WaTeX Arrays and Matrices

WaTeX provides notation for adding arrays and matrices to your questions.

In WaTeX, an array is a simple table with no borders; you can therefore use arrays not only to display tabular data, but also to control the positioning of items such as answer boxes or choices, equations, or even other arrays. For many questions, creating a WaTeX array is simpler and less time-consuming than creating the equivalent table using HTML.

A matrix is a special kind of WaTeX array that automatically displays brackets around it just like mathematical matrices.

You can:

  • add horizontal or vertical ruling for particular cells
  • put arrays and matrices inside of other arrays or matrices

You cannot:

  • directly apply HTML or CSS attributes to change the appearance or size of arrays or matrices
  • span cells horizontally or vertically in arrays or matrices

To use complicated formatting or to allow entry of large amounts of tabular data, you might want to use an HTML table instead of a WaTeX array or matrix.

Creating Arrays

To add an array, type code using the following general syntax:

\begin{array}{alignment}
cell_contents & cell_contents \\
cell_contents & cell_contents
\end{array}

where:

  • \begin{array} starts the array.
  • alignment is a string comprised of one or more lowercase letters l, r, or c specifying left, right, or center alignment for each column. If you use fewer characters than there are columns, the last character defines the alignment for all remaining columns.
  • cell_contents represents anything you want to put in the cell.
  • An ampersand (&) separates each cell in a row.
  • A double backslash (\\) ends each row. This code is not needed to end the last row.
  • \end{array} ends the array.

For example, to align two equations with respect to the equals sign, you could use the following code:

Code

Display

\begin{array}{rcl}
y & = & 3x + 10 \\
2y & = & 4x - 5
\end{array}
y = 3x plus 10 over 2y = 4x minus 5

Creating Matrices

To add a matrix, type code using the following general syntax:

\begin{matrix}{alignment}{rows}
cell_contents & cell_contents \\
cell_contents & cell_contents
\end{matrix}

where:

  • \begin{matrix} starts the matrix.
  • alignment is a string comprised of one or more lowercase letters l, r, or c specifying left, right, or center alignment for each column. If you use fewer characters than there are columns, the last character defines the alignment for all remaining columns.
  • rows specifies the number of rows (1-9) in the matrix and is required to correctly display the brackets around the matrix.
  • cell_contents represents anything you want to put in the cell.
  • An ampersand (&) separates each cell in a row.
  • A double backslash (\\) ends each row. This code is not needed to end the last row.
  • \end{matrix} ends the matrix.

For example, to display a simple 3×2 matrix, you could use the following code:

Code

Display

A = \begin{matrix}{c}{2}
x & y & z\\
a & b & c
\end{matrix}
a = bracket x y z over a b c close bracket

Adding Row or Column Ruling

You can add row or column ruling in arrays and matrices.

  • To add vertical ruling left of any cell, add the following markup in the cell:
    \vline
  • To add horizontal ruling above particular columns in a row, add the following markup anywhere in the row:
    \cline{from-to}

where from and to are the column numbers where the ruling should be displayed. Columns are numbered starting with 0 for the leftmost column. To add ruling above discontinuous columns, use multiple instances of \cline. To add ruling above a single column, specify the same column number for both from and to.

For example:

Code

Display

\begin{matrix}{c}{2}
A & \vline B\\
C & \vline D \cline{0-1}
\end{matrix}
bracket a vertical line b over horizontal line c vertical line d close bracket