2

How to align equation number to come at the bottom when the equation contains cases/rcases?

\documentclass{article}
\usepackage[french,USenglish]{babel}
\usepackage[mmddyyyy]{datetime}
\usepackage{amsmath,amssymb}
\usepackage{amsmath,mathtools,amsfonts,stackengine}

\begin{document}

\begin{equation}
    \mathrm{CTtok_{I_{iv}}} =   \begin{cases}
        \quad \mathcal{T}_{I_{iv}}\\
        \quad \mathrm{C1_I} = \mathrm{e(g, g)}^{\alpha \mathrm{r_i}}\\
        \quad \mathrm{C2_I} = \mathrm{g}^{\beta \mathrm{r_i}}\\
        \begin{rcases}
            \quad \mathrm{C3_{I_y} = g^{q_y(0)}}\\
            \quad \mathrm{C4_{I_y} = H(\mathrm{attr(y)})^{q_y(0)}}\\
        \end{rcases} {\!\normalsize\mathrm{\forall\ y \in Y_I}}\\
    \end{cases}
\end{equation}

\end{document}

enter image description here

pba
  • 527
  • 5
  • 10

2 Answers2

1

You can use numcases from the cases package to number all the equations inside a cases-like environment. \nonumber suppresses the numbering as needed. I additionally use \eqmathbox to have a consistent alignment of the = sign within the cases, and manually set the right brace } for the lower two equations.

enter image description here

\documentclass{article}

\usepackage{mathtools,cases,eqparbox}

% https://tex.stackexchange.com/a/34412/5764 \makeatletter \NewDocumentCommand{\eqmathbox}{o O{c} m}{% \IfValueTF{#1} {\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}} {\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}} \mathpalette\eqmathbox@{#3} } \makeatother

\begin{document}

\begin{numcases}{\mathrm{CTtok_{I_{iv}}} =} \eqmathbox[LHS][r]{\mathcal{T}{I{iv}}} \nonumber \ \eqmathbox[LHS][r]{\mathrm{C1_I}} = \mathrm{e(g, g)}^{\alpha \mathrm{r_i}} \nonumber \ \eqmathbox[LHS][r]{\mathrm{C2_I}} = \mathrm{g}^{\beta \mathrm{r_i}} \nonumber \ \eqmathbox[LHS][r]{\mathrm{C3_{I_y}}} = g^{q_y(0)} \nonumber \ \mathrm{C4_{I_y} = H(\mathrm{attr(y)})^{q_y(0)}} \raisebox{.5\height}[0pt][0pt]{% $\left.\renewcommand{\arraystretch}{1.2}\begin{array}{c} \mathstrut \ \mathstrut \end{array}\right} \forall\ y \in Y_I$% } \end{numcases}

\end{document}

Werner
  • 603,163
0

What you're encountering is that the equation number is normally set on the baseline of the line of display math which will align it with CTok.

What we would need to do is fool LaTeX into thinking that the baseline is at the bottom of the equation. To do this, we'll put the math inside a box. The gotcha is that we need to make a box that has its baseline lined up with the baseline of the contents of the last line of the multi-line expression.

Here's what I came up with.

\NewDocumentEnvironment{bnequation}{} 
   {
     \begin{equation}
     \vbox\bgroup % ❶
       \hbox\bgroup % ❷
          $\displaystyle % ❸
   }
   {
       $\egroup % ❹
       \kern-\dp\strutbox % ❺
     \egroup
     \end{equation}
   }

We create a new document environment¹ named to indicate it's a bottom-numbered equation. Then inside an equation environment, we first open up a \vbox. Note that we use \bgroup ❶ instead of { here to allow us to spread out the argument to \vbox between the \begin and \end commands. We will stack up a box and a kern inside the \vbox to allow us to choose where the baseline of the box will be.

Then we put a \hbox² inside the \vbox ❷. If we had just a bare \hbox, it would still have the baseline of the math that we're trying to avoid. Then we enter math mode and make sure that we're in \displaystyle. ❸

In the \end definition, we close out our math and \hbox ❹ and then we need to put a vertical kern ❺ so that we can make the baseline of the \vbox the bottom of the whole thing rather than the baseline of the \hbox. I had originally used \kern0pt here, but the alignment of the equation number was off because it aligned with the overall bottom of the math rather than the bottom of the last line. Fortunately, we have a pretty good way of guessing that last line's depth³. LaTeX maintains a box called \strutbox⁴ which is represents the spacing above and below the baseline for normal typesetting. We can use its depth to guess at the depth of the last line and kern a negative amount equal to that depth.⁵

The end result is: output of the environment


  1. As always, preferring \NewDocumentEnvironment over \newenvironment.
  2. And again \bgroup for {.
  3. We can't just look at the depth of the \hbox. Remember its baseline is going to be the baseline of CTok so the depth will be much larger than we might have guessed.
  4. This is theoretically font-dependent. A typeface, say, with very long descenders and short ascenders would need a differently-configured \strutbox. Fortunately, I don't know of any text typeface that, with standard leading, doesn't comfortably fit within the bounds of the LaTeX strut.
  5. This isn't fool-proof, especially with mathematics. You might have something like \sum_{i=0} on that last line which will push the depth further than you expect and mess up the alignment. Dealing with this case is left as an exercise to the reader (hint: provide an optional argument to the environment that lets the user override the amount of that final kern).
Don Hosek
  • 14,078