# Aligning Equations with Cases

So I am trying to get something like this on LaTeX: (Source: Optimal Control Theory by Donald Kirk)

My current LaTeX code:

\begin{align*}
u^*\left(t\right) &= -1, &t\in\left[t_0, t_f\right], c \geq 1\\ u^*\left(t\right) &= \begin{cases}
0, &t\in\left[t_0, t_1\right)\\
-1, & t\in\left[t_1, t_f\right]
\end{cases} & 0 < c < 1\\
u^*\left(t\right) &= \begin{cases}
0, &t\in\left[t_0, t_2\right)\\
1, & t\in\left[t_2, t_f\right]
\end{cases} & -1 < c < 0\\
u^*\left(t\right) &= 1, &t\in\left[t_0, t_f\right], c \leq -1\\
u^*\left(t\right) &= 0, &t\in\left[t_0, t_f\right], c = 0
\end{align*}

Current output:

What is the proper way of aligning this?

Two plus one options using alignat.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{2}
u^*(t) &= -1, &&t\in[t_0, t_f], c \geq 1\\
u^*(t) &= \begin{cases}
0, \\
-1,
\end{cases}&& \def\arraystretch{1.2}\begin{array}{@{}l}
t\in[t_0, t_1)\\
t\in[t_1, t_f],
\end{array}
0 < c < 1\\
u^*(t) &= \begin{cases}
0, \\
1,
\end{cases} &&\def\arraystretch{1.2}\begin{array}{@{}l}
t\in[t_0, t_2)\\
t\in[t_2, t_f]
\end{array}
-1 < c < 0\\
u^*(t) &= 1, &&t\in[t_0, t_f], c \leq -1\\
u^*(t) &= 0, &&t\in[t_0, t_f], c = 0
\end{alignat*}

\begin{alignat*}{3}
u^*(t) &= -1, &&t\in[t_0, t_f], &&c \geq 1\\
u^*(t) &= \begin{cases}
0, \\
-1,
\end{cases}&& \def\arraystretch{1.2}\begin{array}{@{}l}
t\in[t_0, t_1)\\
t\in[t_1, t_f],
\end{array}
&&0 < c < 1\\
u^*(t) &= \begin{cases}
0, \\
1,
\end{cases} &&\def\arraystretch{1.2}\begin{array}{@{}l}
t\in[t_0, t_2)\\
t\in[t_2, t_f]
\end{array}
&&-1 < c < 0\\
u^*(t) &= 1, &&t\in[t_0, t_f], &&c \leq -1\\
u^*(t) &= 0, &&t\in[t_0, t_f], &&c = 0
\end{alignat*}
\end{document}

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat*}{2}
u^*\left(t\right) &= -1, &t\in\left[t_0, t_f\right], c \geq 1\\
u^*\left(t\right) &= \begin{cases}
0, &t\in\left[t_0, t_1\right)\\
-1, & t\in\left[t_1, t_f\right]
u^*\left(t\right) &= \begin{cases}
0, &t\in\left[t_0, t_2\right)\\
1, & t\in\left[t_2, t_f\right]
\end{cases} & -1 < c < 0\\
u^*\left(t\right) &= 1, &t\in\left[t_0, t_f\right], c \leq -1\\
u^*\left(t\right) &= 0, &t\in\left[t_0, t_f\right], c = 0
\end{alignat*}
\end{document}

An alternative way to write your equations:

\documentclass{article}
\usepackage{mathtools}

\begin{document}
$u^*(t) = \begin{cases} \begin{rcases} -1 & t\in[t_0, t_f] \end{rcases} & c \geq 1 \\[1ex] \kern-\nulldelimiterspace \begin{rcases} \hphantom{-} 0 & t\in[t_0, t_1)\\ -1 & t\in[t_1, t_f] \end{rcases} & 0 < c < 1 \\[3ex] \kern-\nulldelimiterspace \begin{rcases} \hphantom{-} 0 & t\in[t_0, t_2)\\ -1 & t\in[t_2, t_f] \end{rcases} & -1 < c < 0 \\[1ex] \begin{rcases} \hphantom{-} 1 & t\in[t_0, t_f] \end{rcases} & c \leq -1 \\ \begin{rcases} \hphantom{-} 0 & t\in[t_0, t_f] \end{rcases} & c = 0 \\ \end{cases}$
\end{document}

Very ad hoc, but it does the job. Not that I find that presentation very appealing.

\documentclass{article}
\usepackage{amsmath}

\begin{document}


\end{document}

• This is the only answer (so far) that gets the spaces after the braces as in the original. – Toby Bartels Apr 19 at 8:52
• @TobyBartels It is actually slightly different from the original, where the “for” conditions are not well aligned (for no apparent reason). It wouldn't be difficult to emulate the original also under this respect. – egreg Apr 19 at 9:08
• That's true. There's a pattern to that misalignment: more space before ‘for’ when it covers two lines than when it covers only one. You could add \, at the end of the definition of \sys to mimic that. Another thing is that there should be less space before the ‘for’ text than before the conditions on $t$ (which makes some sense, since both of these clauses are conditions in the definition by cases, to be separated more from the values of $u^*$ than from each other); maybe the 6em in the definition of \cond should be 5em? – Toby Bartels Apr 20 at 10:55
• (Off topic, how does one get tex.se to parse TeX in comments? This happens automatically on math.se.) – Toby Bartels Apr 20 at 11:21
• @TobyBartels The spacing is open to personalization. Here MathJax is not used, because it wouldn't make sense: we're more interested in code rather than in approximations of the output. – egreg Apr 20 at 11:40