[Tex/LaTex] Add line break to one line of a multi-line equation

alignequationsline-breaking

I am writing an equation consisting of many lines, however, one particular line is very long and I want to break into a new line.

For example:

\begin{equation}
    \begin{aligned}
    &   \text{minimise}     &&  COST = A + B \\
    &   \text{subject to}   &&  A = A_1 + A_2 \\
    &                       &&  B = B_1 + B_2 + B_3 + B_4 + B_5 + B_6 + B_7 \\ % this line is too long
    \end{aligned}
\end{equation}

Based on above example, I want to add a line break into the last line.

Best Answer

If it is just breaking, you can use multlined from mathtools (which is an extended form of amsmath)

\documentclass[a4paper]{article}
\usepackage{mathtools}

\begin{document}
    \begin{equation}
    \begin{aligned}
    &   \text{minimise}     &&  COST = A + B \\
    &   \text{subject to}   &&  A = A_1 + A_2 \\
    &                       &&  B = \!\begin{multlined}[t]
                                        B_1 + B_2 + B_3 + B_4 + B_5 \\
                                           + B_6 + B_7  % this line is too long
                                    \end{multlined}
    \end{aligned}
\end{equation}
\end{document}

enter image description here