[Tex/LaTex] Aligning plain `align` and `cases`

aligncasesequationshorizontal alignment

The cases environment works very well for enumerating cases within a large left bracket. I'd like to be able to combine it with the align environment so that equals-signs and conditions also line up:

\item \begin{align*}
T_{in\ general}\left(n\right)&=aT\left(\frac{n}{b}\right) + n^{c},\   &a\geq1, b\geq1, c>0
 \end{align*}

\[T_{cases}\left(n\right)= 
   \begin{cases}
   \Theta\left(n^{\log_{b}a}\right) &a>b^{c}\\
   \Theta\left(n^{c}\log_{b}n\right) &a=b^{c}\\
   \Theta\left(n^{c}\right) &a<b^{c}
   \end{cases}\]

Separate align and case environments do not share alignments:

enter image description here

Is there a reasonably simple way to get (say) the leftmost equals-signs in the two equations here to line up, and separately from them the conditions ("a…")?

Best Answer

It is fairly elementary to align both equations, as well as their variable domains, when defining your own "cases environment" via an array:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{align*}
  T_{\text{in general}}\left(n\right) &= aT\left(\frac{n}{b}\right) + n^{c}, && a\geq 1, b\geq 1, c>0 \\
  & && a>b^{c} \\
  T_{\text{cases}}\left(n\right) &= 
    \smash{\left\{\begin{array}{@{}l@{}}
      \Theta\left(n^{\log_{b}a}\right) \\[\jot]
      \Theta\left(n^{c}\log_{b}n\right) \\[\jot]
      \Theta\left(n^{c}\right)
    \end{array}\right.} && a=b^{c} \\
  & && a<b^{c}
\end{align*}
​\end{document}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Some minor alignment adjustments were made (like using additional & alignment specifiers), as well as \smashing the "cases environment" and adding the [\jot] line skip. \smash removed any vertical height from it's argument, while \jot is a specific 3pt skip provided by LaTeX.

From a typesetting point of view, note the use of \text{...} in the subscripts. This macro is offered by amsmath and allows text to be typeset in the regular way, while still adjusting for the relative size of the font depending on the placement.

Related Question