How to align piecewise functions?
The quick fix is a simple addition of two ampersands before opening the large curly brackets. In the amsmath
align
environment, along with the starred version, the ampersand tells LaTeX what elements should be aligned.
\begin{align*}
&\left\{
\begin{array}{ll}
i = x^2 + y^2 \\
j = a^2 + b^2 \\
\end{array}
\right.
\\
&\left\{
\begin{array}{ll}
i = 1 \\
j = 2 \\
\end{array}
\right.
\end{align*}
Perhaps the following code using split
is a little better to align the =
signs, although it's a matter of taste. The ampersand once again allows you to align the brackets on one level, and the equality signs on the level down. This is done inside the starred equation
environment to allow split
to be used, which is provided by the amsmath
package.
\begin{equation*}
\begin{split}
&\left\{
\begin{split}
i &= x^2 + y^2 \\
j &= a^2 + b^2 \\
\end{split}
\right.
\\
&\left\{
\begin{split}
i &= 1 \\
j &= 2 \\
\end{split}
\right.
\end{split}
\end{equation*}
If the reduced space between the bracket and the equations bothers you in this version, you can insert horizontal space, for example with \,
or with \hspace{2pt}
just after the \left\{
of each group. Using \;
spacing in this solution gives the final version of this code:
\begin{equation*}
\begin{split}
&\left\{\;
\begin{split}
i &= x^2 + y^2 \\
j &= a^2 + b^2 \\
\end{split}
\right.
\\
&\left\{\;
\begin{split}
i &= 1 \\
j &= 2 \\
\end{split}
\right.
\end{split}
\end{equation*}
To simplify, in this case, you can use two cases
environments inside a align*
using &
to align both structures:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
&\begin{cases}
\rlap{$i$}\phantom{j} = x^2 + y^2 \\
j = a^2 + b^2
\end{cases}\\
&\begin{cases}
\rlap{$i$}\phantom{j} = 1 \\
j = 2
\end{cases}
\end{align*}
\end{document}
Here is one way of aligning these two components:
\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{align*}
\left\{
\begin{array}{r@{\;}l}
i &= x^2 + y^2 \\
j &= a^2 + b^2
\end{array}
\right.
\\
\left\{
\begin{array}{r@{\;}l}
i &= \rlap{1}\phantom{x^2 + y^2} \\
j &= \rlap{2}\phantom{a^2 + b^2}
\end{array}
\right.
\end{align*}
\end{document}
You didn't use any column separation &
in your array
. I've inserted that at the alignment point (before =
). Otherwise you would have noticed the difference in the unaligned equality signs due to different widths of i
and j
. I also changed your ll
column specification into r@{\;}l
to r
ight-align the left-hand side, and l
eft-align the right-hand side, plus add the appropriate spacing \;
between the relational operator.
The use of the \rlap
(short for r
ight overlap
) and \phantom
(leaves space without typesetting) combination is aimed at making the lower array
have the same width as the upper one, thereby establishing the appropriate horizontal spacing.