Vertically centred equation number in multiline equation while maintaining alignment with other equations in flalign environment

flalignvertical alignment

How do I centre the equation number of a single multiline equation in a flalign environment while maintaining alignment with other equations at the equals sign?

Basically, I want this

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{flalign}
            AAA &= 2 X Y - D Z & \\
            B &= 2 X Y \left( h_1 v_1 + v_2 \right) & \nonumber  \\
                & \qquad - X^3 \left( 2 h_2 v_2 + K_2 \right) & 
\end{flalign}

\end{document}

but with the equation number (2) centred between the two lines of the second equation.

I've seen several answers to this question, but they either involve only a single multiline equation that does not need to be aligned with other equations (e.g. Have one centred equation number in the flalign enviroment), in which case the centred equation number is easily achieved using aligned or split, or it is a scenario where the expressions to the left of the equals sign of both equations just happen to have the same length and thus align naturally (e.g. Aligning multiline equation to the left with only one equation number).

Edit: here is the screenshot.

enter image description here

Best Answer

I suggest you place rows 2 and 3 inside nested aligned environments.

The following screenshot shows the outputs of both your original code and the suggested replacement code.

enter image description here

Speaking for myself, I can't help but wonder what you could possibly be trying to achieve by centering the second equation number across rows 2 and 3 of the 3-row construct. That said, I also can't fathom why you're using an flalign environment instead of an align environment.

\documentclass{article}
\usepackage{mathtools,calc,xcolor}
\newcommand\mybox[1]{%
   \parbox{\widthof{$AAA$}}{\raggedleft$\displaystyle #1 $}}
\begin{document}

\noindent
\textcolor{red}{before}
\begin{flalign}
            AAA &= 2 X Y - D Z & \\
            B &= 2 X Y \left( h_1 v_1 + v_2 \right) & \nonumber  \\
                & \qquad - X^3 \left( 2 h_2 v_2 + K_2 \right) & 
\end{flalign}

\bigskip\noindent
\textcolor{red}{after}
\begin{flalign}
       &AAA = 2 X Y - D Z & \\
       &\begin{aligned}
          \begin{aligned}
            &\mybox{B} = 2 X Y ( h_1 v_1 + v_2 )  \\
            & \qquad\qquad - X^3 ( 2 h_2 v_2 + K_2 ) 
          \end{aligned}
        \end{aligned}
\end{flalign}
    
\end{document}
Related Question