# Nested left and right braces

I want to align three left braced equations, the first two with some conditions and also right braced with a range of validity. The third equation will not have any conditions, but must have another range of validity. The three equations have to be aligned at left, the two conditions also aligned at left, and the ranges also aligned at left. I have tried to nest left and right braces using the construction below, but it didn't work, because the third line gets not aligned. I'd appreciate having some help in this issue.

\newenvironment{rcases}
{\left.\begin{aligned}}
{\end{aligned}\right\}}
\newenvironment{lcases}
{\left\{\begin{aligned}}
{\end{aligned}\right.}
\begin{equation*}
\psi_n(x)=
\begin{lcases}
\begin{rcases}
\cos(n\pi x/a)\,, &\text{  $n$ even}\\
\sen(n\pi x/a)\,, &\text{  $n$ odd}
\end{rcases}                  &\text{, } \abs{x} \le a/2\\
0\,,                        &\text{  } \abs{x} > a/2
\end{lcases}
\end{equation*}

• Welcome to TeX.SX! Jun 16 '18 at 15:44
• Can you make your example complete, so it can be compiled without modifications? I assume \sen should be \sin, and \abs is not a standard command (I think). That said, amsmath already has a cases environment, and mathtools (which extends amsmath) has an rcases environment. Why not use those? Jun 16 '18 at 16:09

With cases and rcases from mathtools, instead of your custom lcases/rcases, and moving a comma, you get this: Is that what you're after?

\documentclass{article}
\usepackage{mathtools}
\newcommand\abs{}
\begin{document}
\begin{equation*}
\psi_n(x)=
\begin{cases}
\begin{rcases}
\cos(n\pi x/a)\,, &\text{  $n$ even}\\
\sin(n\pi x/a)\,, &\text{  $n$ odd}
\end{rcases}                  &\text{, } \abs{x} \le a/2\\
0                           &\text{, } \abs{x} > a/2
\end{cases}
\end{equation*}
\end{document}


Use cases for the outer alignment. However, I think it's more helpful for the reader to just use three cases.

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\sen}{sen}
\newcommand{\abs}{\lvert#1\rvert}

\newenvironment{rcases}
{\left.\begin{aligned}}
{\end{aligned}\right\}}

\begin{document}

\begin{equation*}
\psi_n(x)=
\begin{cases}
\begin{rcases}
\cos(n\pi x/a)\,, &\text{  $n$ even}\\
\sen(n\pi x/a)\,, &\text{  $n$ odd}
\end{rcases},               &\abs{x} \le a/2\\
0\,,                      &\abs{x} > a/2
\end{cases}
\end{equation*}

\begin{equation*}
\psi_n(x)=
\begin{cases}
\cos(n\pi x/a)\,, &\text{$\abs{x} \le a/2$, $n$ even} \\
\sen(n\pi x/a)\,, &\text{$\abs{x} \le a/2$, $n$ odd} \\
0\,,              &\abs{x} > a/2
\end{cases}
\end{equation*}

\end{document} I would suggest using nested array structure to avoid defining \newenvironment, here is how

\usepackage{amssymb}
\usepackage{mathtools}

\begin{document}

\begin{equation*}
\psi _n \left( x \right) = \left\{ \begin{array}{ll}
\left. \begin{array}{lc}
\cos{\frac{n \pi x}{a}} , & n~\mathrm{even} , \\
\sin{\frac{n \pi x}{a}} , & n~\mathrm{odd} , \\
\end{array} \right\} & x \leqslant \frac{a}{2} \\
\left. \begin{array}{l}
0 , \\
\end{array}\right. & x > \frac{a}{2} \\
\end{array} \right.
\end{equation*}

\end{document}


And here is how its output looks like The last line has to be written with another array in order to get aligned with equations in first two lines.