[Tex/LaTex] multi-line equation in equation environment

amsmathequations

I'm trying to write the following equation using amsmath package in equation envoronment:

enter image description here

and break it into multiple lines using the following code

\begin{equation}
    \label{eq:eqn1}
        \begin{aligned}
            \vec{f}{}' &=\vec{\nabla}{f}                \\
                       &=\vec{\nabla}{f\left ( x, y, z \right )}                \\
                       &\approx \left ( \frac{1}{2} \left ( f\left ( x-1, y, z \right ) + f\left ( x+1, y, z \right ) \right ),  \\
                       &\qquad \frac{1}{2} \left ( f\left ( x, y-1, z \right ) + f\left ( x, y+1, z \right ) \right ),      \\
                       &\qquad \frac{1}{2} \left ( f\left ( x, y, z-1 \right ) + f\left ( x, y, z-1 \right ) \right ) \right )
        \end{aligned}
\end{equation}

This is giving me the following output:

enter image description here

I want the alignment and the line breaking the same but the final closing brace is missing here and for which I am getting error message also.

How can I get rid of this error and have the closing brace back in the equation?

Best Answer

You can use & with \left ... right if you load mathtools (needless to load amsmath in this case) and use its \DeclarePairedDelimiter and \MTkillspecial commands. I adapted an example in the documentation to define a \parens command, which can break across lines. Its starred version adds a pair of implicit \left \right around the parentheses. Alternatively to fine-tune the size of the parentheses, you can use an optional argument: [\big], [\Big], &c.

I took the opportunity to improve your layout and simplify your code, removing all unnecessary pairs of left \right, using a nested aligned environment, the medium-sized fractions from nccmath from the 1/2 coefficients, and the nicer-looking arrows from esvect:

\documentclass{article}
\usepackage{mathtools, nccmath}
\usepackage[b]{esvect} 

    \newcommand\MTkillspecial[1]{% helper macro
    \bgroup
    \catcode`\&=9
    \let\\\relax%
    \scantokens{#1}%
    \egroup
    }
    \DeclarePairedDelimiter\parens()
    \reDeclarePairedDelimiterInnerWrapper\parens{star}{
    \mathopen{#1\vphantom{\MTkillspecial{#2}}\kern-\nulldelimiterspace\right.}
    #2
    \mathclose{\left.\kern-\nulldelimiterspace\vphantom{\MTkillspecial{#2}}#3}}

\begin{document}

\begin{equation}
    \label{eq:eqn1}
        \begin{aligned}
            \vv{f}{}' &=\vv{\nabla}{f} \\
                       &= \vv{\nabla}{f( x, y, z)} \\
                       &\approx \begin{aligned}[t] \parens*{ & \mfrac{1}{2} \bigl( f( x-1, y, z) + f( x+1, y, z) \bigr), \\
                        & \mfrac{1}{2} \bigl( f( x, y-1, z) + f( x, y+1, z) \bigr), \\
                       & \mfrac{1}{2} \bigl( f( x, y, z-1) + f( x, y, z-1) \bigr)
                       }\end{aligned}
        \end{aligned}
\end{equation}

\end{document} 

enter image description here