Anything inside the brackets in \\substack{}
in equation mode will be stacked above each other, with each new line separated by \\\\
. For instance, the code on the left gives us the equation on the right below.
\\substack{
abc\\\\
def
}
$$ \substack{ abc\\ def } $$
Substack allows us to shift each line up and down by adding [{number}em]
right after the \\\\
, on the same line. "em" is a LaTeX unit of length which is roughly the width of an M. When you write [3em]
you're telling substack to shift the next line 3 em units down, and when you write [-2.5em]
, you're telling substack to shift the next line 2.5 em units up. For instance, compare the two blocks of code below and the equation they give us with the first code example
\\substack{
abc\\\\[1em]
def
}
$$ \substack{ abc\\[1em] def } $$
\\substack{
abc\\\\[-0.5em]
def
}
$$ \substack{ abc\\[-0.5em] def } $$
Ok, so that last one looks ugly and why would we want to do that? Well it turns out that if you know how to change the latex font and font color you can make some really pretty overlays just using a substack and shifting subsequent lines, for instance
$$ \substack{ \color{lavender}\text{This is my sentence.}\\[-1em] \text{This is my sentence.} } $$
You can find more elaborate examples in my LaTeX database by looking through the backlinks of this page. Notice that I toggled text mode in this equation. For more on that and changing text color & typeface, see Intro to LaTeX fonts .
You can already do some pretty cool stuff with just stacking vertically and changing font & background colors, but we can add some extra nice effects by shifting lines side to side. There are two ways to do this. First is the low-tech good old fashioned backslash: in LaTeX equation mode, \\
will add a space. Since the columns in substack are centered, we can move text "off center" forcefully by adding blank space characters. If you want to shift your column left, put spaces on the right of the text, and if you want to shift it right, put spaces on the left.
The second option is a bit more elegant and allows for more precise spacing, it involves using an \\hspace
tag. The code \\hspace{3em}
, for instance, will insert 3 em units of horizontal space wherever you put it. Again, if you want to shift your column left, put hspace on the right of the text, and if you want to shift it right, put hspace on the left.