# 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}

\newcommand{\ph}{\hphantom{\bigg\lbrace}}% \newcommand{\cond}[3]{\makebox[3em][l]{#1}{#2}\makebox[6em][l]{#3}}% \newcommand{\sys}[1]{% \biggl\lbrace \begin{array}{@{}l@{}}#1\end{array}% }% \newcommand{\0}{\phantom{-}0}% \begin{aligned} u^*(t)&=\cond{-1,}{\ph}{t\in [0,t_f],}\text{for 1\le c_1} \\ u^*(t)&=\sys{\cond{\0,}{}{t\in[0,t_1)} \\[0.75ex] \cond{-1,}{}{t\in[t_1,t_f],}}\text{for 0<c_1<1}\\ u^*(t)&=\sys{\cond{\0,}{}{t\in[0,t_1')} \\[0.75ex] \cond{-1,}{}{t\in[t_1',t_f],}}\text{for -1<c_1<0}\\ u^*(t)&=\cond{+1,}{\ph}{t\in[0,t_f],}\text{for c_1\le -1}\\ u^*(t)&=\cond{\0,}{\ph}{t\in[0,t_f],}\text{for c_1=0} \end{aligned}

\end{document}


• This is the only answer (so far) that gets the spaces after the braces as in the original. Apr 19, 2020 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. Apr 19, 2020 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? Apr 20, 2020 at 10:55
• (Off topic, how does one get tex.se to parse TeX in comments? This happens automatically on math.se.) Apr 20, 2020 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. Apr 20, 2020 at 11:40