4

I want all equations to bo properly aligned along the '=' sign. But what I get is the following: Consider this MWE

\documentclass{scrreprt}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}  
\begin{align}
        \begin{aligned}
            a &= b + c + d\\
            e &= f\\
            \begin{rcases}
                g &= h\\
                i &= j  
            \end{rcases}
            \quad \forall k < l
        \end{aligned}
    \end{align} 
\end{document}

which produces this: enter image description here

Is there a global solution to fix the alignment and get rid of the extra white space between the left expression and the '=' sign inside the rcases environment?

Thank you in advance!

Saegi
  • 85
  • Related (but do not solve directly the problem): https://tex.stackexchange.com/questions/361790/how-can-i-create-braces-around-aligned-equations https://tex.stackexchange.com/questions/223071/how-to-put-a-curly-brace-in-the-right-of-three-lines-within-an-align-environment – Willie Wong Nov 22 '19 at 16:11

4 Answers4

2

The following automates the spacing correction between the rcases-like construction and the rest of the aligned environment:

enter image description here

\documentclass{article}

\usepackage{mathtools}

\newlength{\mylen}

\begin{document}

\begin{equation}
  \settowidth{\mylen}{$\displaystyle hijk = {}$\,}
  \begin{aligned}
    a &= b + c + d \\
    e &= g         \\
      &\phantom{{}={}}
      \hspace*{-\dimexpr\mylen+\nulldelimiterspace}
        \left.\begin{aligned}
          hijk &= l \\
             m &= n
        \end{aligned}\right\}
        \quad \forall k < l
  \end{aligned}
\end{equation}

\end{document} 

The idea is to set the rcases-like construction using aligned on the RHS of the equation alignment and then move it to the left exactly the right amount so the equality signs line up. \mylen is the correct length, equivalent to the longest LHS of the rcases-like construction, plus an appropriately-spaced = and \, (inserted by aligned).

Werner
  • 603,163
1

Here are three ways: with \MoveEqLeft from mathtools (by trial and error), with an array environment and the bigdelim package, and with blkarray.

Unrelated: needless to load amsmath when you load mathtools(or empheq). This is automatic.

\documentclass{scrreprt}
\usepackage{array, bigdelim}
\usepackage{blkarray}
\usepackage{mathtools}

\begin{document}

\begin{align}
        \begin{aligned}
            a &= b + c + d\\
            e &= f\\
             \MoveEqLeft[0.8]\begin{rcases}
            \begin{aligned}
                g & = h\\
                i & = j
            \end{aligned}
            \end{rcases}
            \quad \forall k < l
        \end{aligned}
    \end{align}
\bigskip
\begin{equation}
        \begin{array}{r @{}>{{}}l@{}l}
            a &= \mathrlap{b+ c + d}\\
            e &= f\\
                g & = h & \,\rdelim\}{2}{*}[\quad$ \forall k < l $]\\
                i & = j
        \end{array}
    \end{equation}
\bigskip

    \begin{equation}
        \begin{blockarray}{r @{}>{{}}l}
            a &= \mathrlap{b+ c + d}\\
            e &= f\\
        \begin{block}{r @{}>{{}}l\Right{\}}{\quad$ \forall k < l $}}
                g & = h \\
                i & = j \\
        \end{block}
        \end{blockarray}
    \end{equation}

\end{document} 

enter image description here

Bernard
  • 271,350
1

With use of the nicematrix package:

\documentclass{article}
\usepackage{nicematrix}
\usetikzlibrary{decorations.pathreplacing,
                calligraphy}
\tikzset{
B/.style = {decorate,
            decoration={calligraphic brace, amplitude=4pt,
            raise=2mm},% for mirroring of brace
            thick,
            pen colour=black}
        }

\usepackage[active,displaymath, tightpage]{preview}% don't use in real document!
\setlength\PreviewBorder{1em}

\begin{document}
    \begin{equation}
    \setlength\arraycolsep{1pt}
\begin{NiceArray}{RL}%
    [code-after={\tikz\draw[B]  (3-2.north east) -- 
                    node[right=7mm] {$\forall k < l$}
                                (4-2.south east);
                }
    ]
a & = b + c + d  \\
e & = f          \\
g & = h          \\
i & = j           
\end{NiceArray}
    \end{equation}
\end{document}

enter image description here

Note: for final looks you need to compile document at least twice.

Bernard
  • 271,350
Zarko
  • 296,517
0

If you don't mind manually adjusting the spacing so that they line up correctly on the left, you can do as follows:

\documentclass{article}
\usepackage{mathtools}
\begin{document}  
\begin{equation}
    \begin{aligned}
        a &= b + c + d\\
        e &= f\\
          & \mkern-15mu \begin{rcases} \begin{aligned}
                g &= h\\
    i &= j  \end{aligned}
        \end{rcases}
        \quad \forall k < l
    \end{aligned}
\end{equation} 
\end{document}

To keep the correct spacing, the interior of rcases is wrapped again in aligned so that the spacing between the terms are the same as outside the rcases. The whole thing is placed on the right of the alignment point, and then manually shifted back left so that the equals signs line-up. The amount of shifting of course depends on the actual expressions involved, so you will have to play with it by hand.

Willie Wong
  • 24,733
  • 8
  • 74
  • 106