# How to wrap an equation while aligning the equal sign?

The equation exceed the margin, and I want to wrap the equation while aligning the equal sign, the following is my original codes:

 \begin{eqnarray}\label{ 7}
\begin{split}
\beta_{ij}^{js-js}\mid z_{ij}  &=  \left(1 -\left(\frac{n -2}{\lVert \boldsymbol{z_j}\rVert^2-\frac{2(n-2)\sum_iz_{ij}^2}{\lVert \boldsymbol{z_{i}}\rVert^2}+\frac{(n-2)^2\sum_iZ_{ij}^2}{\lVert \boldsymbol{z_i}\rVert^4}} +\frac{\text{p}-2}{\lVert \boldsymbol{z_{i}} \rVert^2}  -\frac{\left(n -2\right)\left(\text{p}-2\right)}{\lVert \boldsymbol{z_{i}} \rVert^2 \left(\lVert \boldsymbol{z_j}\rVert^2-\frac{2(n-2)\sum_iz_{ij}^2}{\lVert \boldsymbol{z_{i}}\rVert^2}+\frac{(n-2)^2\sum_iZ_{ij}^2}{\lVert \boldsymbol{z_i}\rVert^4}\right)} \right)z_{ij}
\\&=\left(1 -\left(\frac{n -2}{\lVert \boldsymbol{z_j}\rVert^2-k_j} +\frac{\text{p}-2}{\lVert \boldsymbol{z_{i}} \rVert^2} - \frac{\left(n -2\right)\left(\text{p}-2\right)}{\lVert \boldsymbol{z_{i}} \rVert^2 \left(\lVert \boldsymbol{z_j}\rVert^2-k_j\right)} \right)\right) z_{ij}
\end{split}
\end{eqnarray} The result that I want I tried \right\\ \left before the cutting position, but I didn't get the desire result. I also try the following solution I checked online, but still not work in my case. Could anyone offer me a help? Thank you.

\begin{eqnarray*}
y & = & x \\
& & {} + x1 \\
& & {} + x2
\end{eqnarray*}

• You should never use eqnarray it is completely obsoleted by the amsmath package which you must also have loaded as you have split defined. – David Carlisle May 14 '17 at 20:35

## 5 Answers

You could use equation and \begin{aligned}[b] (as @Mico kindly suggested), this is under the assumption you want only a single number for the equation. With the [b] option the eqn number is printed on the bottom line

\documentclass{article}
\usepackage{amsmath,mathtools}
\begin{document}
\begin{equation}
\begin{aligned}[b]
\beta_{ij}^{js-js}\mid z_{ij}  &=
\Biggl(1 -\Biggl(\frac{n -2}{\lVert \boldsymbol{z_j} \rVert^2 - \frac{2(n-2)\sum_iz_{ij}^2}{\lVert \boldsymbol{z_{i}}\rVert^2}+\frac{(n-2)^2\sum_iZ_{ij}^2}{\lVert \boldsymbol{z_i}\rVert^4} } +
\frac{\mathrm{p}-2}{\lVert \boldsymbol{z_{i}} \rVert^2} \\
&\qquad-\frac{(n -2)(\mathrm{p}-2)}{\lVert \boldsymbol{z_{i}} \rVert^2 \Bigl(\lVert \boldsymbol{z_j}\rVert^2  -\frac{2(n-2)\sum_iz_{ij}^2}{\lVert \boldsymbol{z_{i}}\rVert^2}+\frac{(n-2)^2\sum_iZ_{ij}^2}{\lVert \boldsymbol{z_i}\rVert^4}\Bigr)} \Biggr)  \Biggr) z_{ij}
\\
&=\biggl(1 -\biggl(\frac{n -2}{\lVert \boldsymbol{z_j}\rVert^2-k_j} +\frac{\text{p}-2}{\lVert \boldsymbol{z_{i}} \rVert^2} - \frac{(n -2)(\mathrm{p}-2)}{\lVert \boldsymbol{z_{i}} \rVert^2 (\lVert \boldsymbol{z_j}\rVert^2-k_j)} \biggr)\biggr) z_{ij}
\end{aligned}
\end{equation}
\end{document}


giving What I did, except using the aforementioned environment is:

1. aligned the second row with a \qquad space, in order to give it an "indent", which is what I think you wanted

2. Got rid of left and right which were abused (it's best to manually scale the parentheses with commands such as biglbigr and so on, to have better spacing and scaling). you could tweak it if you want

3. I replaced text with mathrm (text gives the current font)

• It seems kind of odd to place the equation number on the middle line. Consider replacing the split environment with an aligned[b] environment? – Mico May 14 '17 at 21:13
• @Mico if I manage to correct it I'll do it now thanks, you're right – Moriambar May 14 '17 at 21:27
• Congrats on passing the 4K rep mark! – Mico May 14 '17 at 21:43
• there's a closing parenthesis missing in the first equation, and the initial paren in the same equation should be larger, the same size as the one preceding the fraction. – barbara beeton May 14 '17 at 22:15
• @barbarabeeton I'll try and correct this as soon as I come home from work, which will be in around 12 hours, thanks – Moriambar May 15 '17 at 6:16

Never use eqnarray.

With some simplifications and changes in the input, notably

• \norm{...} instead of \lVert...\rVert
• \bm instead of \boldsymbol; also \bm{z_j} and similar have been changed to \bm{z}_j because the subscript should not be bold
• \text{p} became p; if you really need it upright, it should be \mathrm{p}
• the complicated denominator in the third summand in the top equation has been set as a product
• useless \left and \right removed
• some \, for spacing the big parentheses added

I left \label{7}, although I suggest a more meaningful name. In any case \label{ 7} is dubious, as it requires \ref{ 7} which is awkward.

\documentclass{article}
\usepackage{amsmath,mathtools,bm}

\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}

\begin{document}

\begin{equation}\label{7}
\begin{split}
\beta_{ij}^{js-js}\mid z_{ij}
&=\Biggl(
1-\Biggl(\,\frac{n-2}{
\norm{\bm{z}_j}^2-
\frac{2(n-2)\sum_i z_{ij}^2}{\norm{\bm{z}_{i}}^2}+
\frac{(n-2)^2\sum_i Z_{ij}^2}{\norm{\bm{z}_i}^4}
}+
\frac{p-2}{\norm{\bm{z}_{i}}^2}
\\
&
\hphantom{{}=\Biggl(1}-
\frac{1}{\norm{\bm{z}_i}^2}
\frac{(n-2)(p-2)}{
\norm{\bm{z}_j}^2-\frac{2(n-2)\sum_iz_{ij}^2}{\norm{\bm{z}_{i}}^2}+
\frac{(n-2)^2\sum_iZ_{ij}^2}{\norm{\bm{z}_i}^4}
}
\,\Biggr)\Biggr)z_{ij}
\\[2ex]
&=\biggl(
1-\biggl(\,
\frac{n-2}{\norm{\bm{z}_j}^2-k_j}+
\frac{p-2}{\norm{\bm{z}_{i}}^2}-
\frac{(n-2)(p-2)}{\norm{\bm{z}_{i}}^2 (\norm{\bm{z}_j}^2-k_j)}
\,\biggr)
\biggr) z_{ij}
\end{split}
\end{equation}

\end{document} I replaced eqnarray by align and adjusted some of the markup. (the use of \boldsymbol still looks a bit suspect. \documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align}\label{zz}% don't use numbers as labels.
\beta_{ij}^{js-js}\mid z_{ij}  &= \Bigl(1 -
\bigl(\frac{n -2}{\lVert \boldsymbol{z_j}\rVert^2-\frac{2(n-2)\sum_iz_{ij}^2}{\lVert \boldsymbol{z_{i}}\rVert^2}+\frac{(n-2)^2\sum_iZ_{ij}^2}{\lVert \boldsymbol{z_i}\rVert^4}} +\frac{\mathrm{p}-2}{\lVert \boldsymbol{z_{i}} \rVert^2}\notag\\
&\qquad
-\frac{(n -2)(\mathrm{p}-2)}{\lVert \boldsymbol{z_{i}} \rVert^2 (\lVert \boldsymbol{z_j}\rVert^2-\frac{2(n-2)\sum_iz_{ij}^2}{\lVert \boldsymbol{z_{i}}\rVert^2}+\frac{(n-2)^2\sum_iZ_{ij}^2}{\lVert \boldsymbol{z_i}\rVert^4})}
\bigr)z_{ij}
\\&=(1 -(\frac{n -2}{\lVert \boldsymbol{z_j}\rVert^2-k_j} +\frac{\mathrm{p}-2}{\lVert \boldsymbol{z_{i}} \rVert^2} - \frac{(n -2)(\mathrm{p}-2)}{\lVert \boldsymbol{z_{i}} \rVert^2 (\lVert \boldsymbol{z_j}\rVert^2-k_j)} )
\Bigr) z_{ij}
\end{align}
\end{document}


Whatever else you do, don't use eqnarray -- it's badly deprecated.

I suggest using a single align environment, not using a split environment, replacing all \boldsymbol directives with \bm (from the bm package), and defining a \norm macro to cut down on all the \lVert and \rVert directives. For extra legibility, consider using square brackets in addition to round parentheses. And, rather than \text{p}, write \mathrm{p}, and don't overuse \left and \right. \documentclass{article}
\usepackage{mathtools,bm}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\begin{document}
\begin{align}
\beta_{ij}^{js-js} \bigm| z_{ij}
&=  \left[1 -\left(
\frac{n -2}{\norm{\bm{z_j}}^2
-\frac{2(n-2)\sum_iz_{ij}^2}{\norm{\bm{z_{i}}}^2}
+\frac{(n-2)^2\sum_iZ_{ij}^2}{\norm{\bm{z_i}}^4}}
+\frac{\mathrm{p}-2}{\norm{\bm{z_{i}}}^2}
\right.\right. \notag\\
&\qquad\quad -\left.\left.\frac{(n-2)(\mathrm{p}-2)}{\norm{\bm{z_{i}}}^2
\Bigl( \norm{\bm{z_j}}^2
-\frac{2(n-2)\sum_iz_{ij}^2}{\norm{\bm{z_{i}}}^2}
+\frac{(n-2)^2\sum_iZ_{ij}^2}{\norm{\bm{z_i}}^4} \Bigr)}
\right)\!\right] z_{ij}\notag\\[2ex]
&=\biggl[1 -\biggl(\frac{n -2}{\norm{\bm{z_j}}^2-k_j}
+\frac{\mathrm{p}-2}{\norm{\bm{z_{i}}}^2}
-\frac{(n-2)(\mathrm{p}-2)}{\norm{\bm{z_{i}}}^2
(\norm{\bm{z_j}}^2-k_j)} \biggr)\biggr] z_{ij} \label{eq:7}
\end{align}
\end{document}


with multlined from mathtools and consider some suggestion from above answers: \documentclass{article}
\usepackage{geometry}
\usepackage{mathtools}

\begin{document}
\begin{align}\label{eq:num7}
\beta_{ij}^{js-js}\Big| z_{ij}
& = \begin{multlined}[t][0.7\linewidth]
\left[1 -
\left(\frac{n -2}
{\lVert\boldsymbol{z_j}\rVert^2
-\frac{2(n-2)\sum_iz_{ij}^2}
{\lVert\boldsymbol{z_{i}}\rVert^2}
+\frac{(n-2)^2\sum_iZ_{ij}^2}
{\lVert\boldsymbol{z_i}\rVert^4}}
+\frac{\mathrm{p}-2}
{\lVert\boldsymbol{z_{i}}\rVert^2}
\right.\right.
\\
\left.\left.
-\frac{(n-2)(\mathrm{p}-2)}
{\lVert\boldsymbol{z_{i}}\rVert^2
\Bigl(\lVert\boldsymbol{z_j}\rVert^2
-\frac{2(n-2)\sum_i z_{ij}^2}
{\lVert \boldsymbol{z_{i}}\rVert^2}
+\frac{(n-2)^2\sum_i Z_{ij}^2}
{\lVert \boldsymbol{z_i}\rVert^4}
\Bigr)
} \right)z_{ij}
\right]
\end{multlined}                     \notag  \\[1ex]
& = \left[(1 -\left(\frac{n - 2}
{\lVert\boldsymbol{z_j}\rVert^2-k_j}
+ \frac{\mathrm{p}-2}
{\lVert \boldsymbol{z_{i}} \rVert^2}
- \frac{\left(n -2\right)\left(\mathrm{p}-2\right)}
{\lVert\boldsymbol{z_{i}}\rVert^2
\left(\lVert\boldsymbol{z_j}\rVert^2-k_j\right)}
\right)
\right] z_{ij}

\end{align}
\end{document}

• If you use \sum\limits, you should also enlarge quite a few of the parentheses. – Mico May 14 '17 at 21:15
• @Mico, you have right, I remove \limits. – Zarko May 14 '17 at 22:35
• the size of the opening bracket and parenthesis in the first line doesn't match the size of the closing parenthesis and bracket on the next line. – barbara beeton May 15 '17 at 2:05
• @barbarabeeton, yes, they are :( the paranthesis in denomitar are to big, they should be \Big instead \bigg. corrected. – Zarko May 15 '17 at 2:33