I'm trying to write the following equation using amsmath package in equation envoronment:
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:
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 loadmathtools
(needless to loadamsmath
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 nestedaligned
environment, the medium-sized fractions fromnccmath
from the 1/2 coefficients, and the nicer-looking arrows fromesvect
: