Aligning Elements
When displaying math, it is often useful to align elements, such as when you are writing out a multi-step solution to an equation. To achieve a crisp, aligned look in LaTeX, you can use what are called arrays.
Arrays are useful for displaying multiple steps of an equation.
To work, an array must have a few basic elements:
- \begin{array} at the beginning
- The number of columns and their alignment
- \end{array} at the end
Column number and alignment is indicated by letters within a set of curly braces right after the beginning of the array. The letters are r (right), c (centre), and l (left). The order in which you list the letters will correspond to the columns, i.e., an l in the second position will result in a left-aligned second column.
To separate columns within a row, add an &. You must put an & between each element in the row, but you don’t necessarily need one before the first element or after the last. If you have empty columns in a row, you still need an & to indicate that the column is there, even though it is empty. You should have one less & than there are columns, e.g., if there are five columns, each row should have four &s.
Note that you do not need to declare how many rows there will be before you start writing the array. This provides some flexibility when deciding how many steps of an equation to display.
Finally, to separate rows, use \\ at the end of a row to indicate that a new line should begin immediately after. This symbol is also useful in other instances of LaTeX when you need extra space between lines of an equation.
Here is an example array, without the necessary LaTeX wrappers to enclose:
\begin{array}{rrrcl}
3&+&x&=&4 \\
3-3&+&x&=&4-3 \\
&&x&=&1
\end{array}
Once the LaTeX wrappers are added, the equation will display as:
3 + x = 4
3-3 = x = 4 – 3
x = 1
The first three columns are right aligned, the fourth (where the equal signs are) is centre aligned, and the fifth is left aligned. Different alignments can be beneficial in different equations, so try different configurations until you are satisfied with the result.
I have decided to right-align the 3 on the left-hand side of the equation because I didn’t like the look of the big space that occurred when I left-aligned it. To see what I mean, change the
first r of the column specifications parameter to an l. You may prefer this display, so ahead and try it.
Note that, in the last row, two &s come before x because there are two empty columns.