Curly Bracket over multiple equation

bracketsequations

I have a question regarding the curvy brackets in tex. Didn't find a good solution for the problem yet:

I have the following formulas:

\begin{equation}
  \begin{aligned}
    f(x) &= x + 1 \\
    g(x) &= x + 2 \\
    h(x) &= x + 3 \\
    k(x) &= x + 4 \\
    l(x) &= x + 5 
  \end{aligned}
\end{equation}

Now I want to have a curly bracket around f(x) and g(x) on the right side and want to write some stuff behind the curly bracket. And I also want a curly bracket behind h(x), k(x) and l(x). How can I manage that and also make sure, that all five equations are aligned on the "="-sign?

I just tried to put the formulas in a \begin{rcases} … \end{rcases}, but then the formulas are no longer aligned.

Thank you very much in advance!

Best regards!

Best Answer

You can use nicematrix and its powerful methods.

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

\AtBeginEnvironment{NiceArray}{\tracinglostchars=0 }

\begin{document}

\[
\renewcommand{\arraystretch}{1.2}
\begin{NiceArray}{ @{} r @{} >{{}}c<{{}} @{} l l}
  f(x) &=& x + 1 & \Block{2-1}{\text{whatever}}\\
  g(x) &=& x + 2 \\
  h(x) &=& x + 3 & \Block{3-1}{\text{something else}}\\
  k(x) &=& x + 4 \\
  l(x) &=& x + 5 \\
\CodeAfter
\SubMatrix.{1-3}{2-3}\}
\SubMatrix.{3-3}{5-3}\}
\end{NiceArray}
\]

\end{document}

The strange setting to \tracinglostchars is to avoid spurious warnings (but they deserve some investigation).

The specifications for the columns are the usual ones to mimic aligned, including the setting to \arraystretch. We build two “submatrices”, with empty delimiter on the left and braces on the right, plus two blocks spanning two and three rows respectively.

enter image description here

A couple of LaTeX runs are necessary for the output to stabilize, because ornamentations are set in successive steps after the object has been measured.