Place brace on the right of a subset of aligned equations

alignbracescases

This question is essentially an extension of this question about how to place right braces around cases.

I want to have three equations, all aligned, but I want only the latter two of the equations to be grouped by a right brace. I've tried things like

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{aligned}
        \delta\psi&=i\beta\gamma^{5}\\
        \.
        \delta\sigma&=2\beta\pi\\
        \delta\pi&=-2\beta\sigma
        \right\rbrace
\end{aligned}

which obviously doesn't work, as the linked \left\. ... \right\rbrace can't work across the line break in the aligned environment.

Essentially, I want something like this

enter image description here

but the right brace only connecting the lower two equations.

Any help would be much appreciated!

Best Answer

You can use nicematrix:

\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}

\begin{document}

\[
\setlength{\arraycolsep}{0pt}
\renewcommand{\arraystretch}{1.2}
\begin{NiceArray}{r >{{}}c<{{}} l}
  \delta\psi   &=&  i\beta\gamma^{5} \\
  \delta\sigma &=&  2\beta\pi \\
  \delta\pi    &=& -2\beta\sigma
\CodeAfter\SubMatrix.{2-1}{3-3}\}
\end{NiceArray}
\]

\end{document}

A couple LaTeX runs may be needed in order for the result to be final.

enter image description here

In this particular case, I find it more appealing to use left alignment for the first column: if you change the column specifications into

\begin{NiceArray}{l >{{}}c<{{}} l}

you get

enter image description here

What about text beside the brace? Here we need to better control the intercolumn spaces.

\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}

\begin{document}

\[
\renewcommand{\arraystretch}{1.2}
\begin{NiceArray}{ @{} l @{} >{{}}c<{{}} @{} l l @{} }
  \delta\psi   &=&  i\beta\gamma^{5} \\
  \delta\sigma &=&  2\beta\pi & \Block{2-1}{\text{whatever}}\\
  \delta\pi    &=& -2\beta\sigma
\CodeAfter\SubMatrix.{2-1}{3-3}\}
\end{NiceArray}
\]

\end{document}

enter image description here

Related Question