Spacing

Sometimes elements don’t align perfectly in an array, no matter if you choose left, right, or centre. When things are just a little off, \phantom{} is very useful.

\phantom{} inserts an invisible character, or a ghost character. This is useful when trying to align numbers with different digits or positive and negative numbers.

Say we want to add 3x − 4y = 8 and 5x + 4y = −24 in order to solve for x. Here’s that equation in LaTeX and how it displays:

\)\begin{array}{rrrrrl}
&3x&-&4y&=&\phantom{-0}8 \\
+&5x&+&4y&=&-24 \\
\midrule
&&&\dfrac{8x}{8}&=&\dfrac{-16}{8} \\ \\
&&&x&=&-2
\end{array}\)

3x  –  4y  =      8

+   5x  +  4y  =  -24

8x      -16

8            8

 x     =  -2

Since −24 has two extra characters than 8, we write \phantom{-0} to insert an invisible minus sign and extra digit to push 8 farther to the right.

Notice that the final column is left-aligned. If it were right-aligned, the \phantom{-0} would not be necessary. We have it left-aligned for aesthetic purposes, keeping the −2 closer to the x = in the final row. For time’s sake, it is best to keep LaTeX simple when possible, so remember to experiment with column alignment before resorting to \phantom{}.

Other things to note here are that the plus sign before 5x + 4y = −24 is placed in a separate column, which looks most aesthetically pleasing and true to what we associate with addition, and that there is a new line separating the fractions from the row with x = −2 (notice the double \\ after the fraction code in the LaTeX). This is because fractions often run into whatever is immediately below them, like so:

\)\begin{array}{rrr}
\dfrac{14y}{14}&=&\dfrac{28}{14} \\
y&=&2
\end{array}\)

This is particularly true for consecutive lines that both have fractions:

\)\begin{array}{rrrrr}
y&=&\dfrac{1}{3}x&+&6 \\ \\
y&=&\dfrac{1}{3}(0)&+&6 \\ \\

y&=&0&+&6 \\
y&=&6&&
\end{array}\)

y  =  1 x  +  6

3

y  =  1 (0)  +  6

3

y  =  0  +  6

y  =  6

It may feel awkward to have uneven spacing between lines (since there is no new line separating the last two lines), but it is preferable to have the fractions spaced out and to conserve space elsewhere where possible in order to condense file size.

License

Icon for the Creative Commons Attribution 4.0 International License

LaTeX in Pressbooks: An Introduction and Workflow Copyright © by Caroline Daniels and Arianna is licensed under a Creative Commons Attribution 4.0 International License, except where otherwise noted.

Share This Book