1

How do I correct this alignment problem?

\begin{align}
    & \big[ \boldsymbol{V^{2 (n)}} \big] &\begin{aligned} = \big[ \boldsymbol{B^{\prime (nn)}} \big]^{-1} \big[ \boldsymbol{\widetilde{Q}^{(n)}} \big] &- \big[ \boldsymbol{B^{\prime (nn)}} \big]^{-1} \big[ \boldsymbol{B^{\prime (nm)}} \big] \big[ \boldsymbol{V^{2 (m)}} \big] \\
    &- \big[ \boldsymbol{B^{\prime (nn)}} \big]^{-1} \big[ \boldsymbol{G^{\prime \prime (nm)}} \big] \big[ \boldsymbol{\widetilde{\delta}^{\prime (m)}} \big] - \big[ \boldsymbol{B^{\prime (nn)}} \big]^{-1} \big[ \boldsymbol{G^{\prime \prime (nn)}} \big] \big[ \boldsymbol{\widetilde{\delta}^{\prime (n)}} \big] \\
    \end{aligned} \nonumber \\
    & &\begin{aligned}\label{eqD30} = \big[ \boldsymbol{B^{\prime (nn)}} \big]^{-1} \Big( \big[ \boldsymbol{\widetilde{Q}^{(n)}} \big] - \big[ \boldsymbol{B^{\prime (nm)}} \big] \big[ \boldsymbol{V^{2 (m)}} \big] - \big[ \boldsymbol{G^{\prime \prime (nm)}} \big] \big[ \boldsymbol{\widetilde{\delta}^{\prime (m)}} \big] - \big[ \boldsymbol{G^{\prime \prime (nn)}} \big] \big[ \boldsymbol{\widetilde{\delta}^{\prime (n)}} \big] \Big) \\
    \end{aligned}
\end{align}

enter image description here

  • Remove the starting ampersand in every line. And put the = before the begin aligned. – JPi May 25 '17 at 1:29
  • @JPi It did not help. The alignment is still broken. – janeoh May 25 '17 at 1:40
2

If you use an alignat environment you can define two alignment points. In order to allow the last line to span both, use the \span command.

Full example:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat}{2}
    \big[\boldsymbol{V^{2 (n)}}\big] &= \big[\boldsymbol{B^{\prime (nn)}}\big]^{-1} \big[\boldsymbol{\widetilde{Q}^{(n)}}\big] &&- \big[\boldsymbol{B^{\prime (nn)}}\big]^{-1} \big[\boldsymbol{B^{\prime (nm)}}\big] \big[\boldsymbol{V^{2 (m)}}\big]\nonumber\\
    & &&- \big[\boldsymbol{B^{\prime (nn)}}\big]^{-1} \big[\boldsymbol{G^{\prime \prime (nm)}}\big] \big[\boldsymbol{\widetilde{\delta}^{\prime (m)}}\big] - \big[\boldsymbol{B^{\prime (nn)}}\big]^{-1} \big[\boldsymbol{G^{\prime \prime (nn)}}\big] \big[\boldsymbol{\widetilde{\delta}^{\prime (n)}}\big]
    \nonumber\\
    &= \big[\boldsymbol{B^{\prime (nn)}}\big]^{-1} \Big(\big[\boldsymbol{\widetilde{Q}^{(n)}}\big] - \big[\boldsymbol{B^{\prime (nm)}}\big] \big[\boldsymbol{V^{2 (m)}}\big] - \big[\boldsymbol{G^{\prime \prime (nm)}}\big] \big[\boldsymbol{\widetilde{\delta}^{\prime (m)}}\big] - \big[\boldsymbol{G^{\prime \prime (nn)}}\big] \big[\boldsymbol{\widetilde{\delta}^{\prime (n)}}\big]\Big) \span \span \label{eqD30}
\end{alignat}
\end{document}

This produces:

output

Note the shifted equation number as the whole thing is too wide to fit the text with the default margins.

See also here for a related question and a possible alternative solution with \llap or \rlap.

  • Woah so simple, it went over my head! Thank you very much! – janeoh May 25 '17 at 1:54
3

Nest aligned. Since this is just one equation, I used split for the outer alignment.

\documentclass{article}
\usepackage{geometry} % just for not getting an overfull box
\usepackage{amsmath,bm}

\begin{document}

\begin{equation}
\label{eqD30}
\begin{split}
[\bm{V}^{2 (n)}] 
  &= \begin{aligned}[t]
     [\bm{B}^{\prime (nn)}]^{-1} [\widetilde{\bm{Q}}^{(n)}] 
       &- [\bm{B}^{\prime (nn)}]^{-1} [\bm{B}^{\prime (nm)}] [\bm{V}^{2 (m)}] \\
       &- [\bm{B}^{\prime (nn)}]^{-1} [\bm{G}^{\prime \prime (nm)}] 
          [\widetilde{\bm{\delta}}^{\prime (m)}]
        - [\bm{B}^{\prime (nn)}]^{-1} [\bm{G}^{\prime \prime (nn)}]
          [\widetilde{\bm{\delta}}^{\prime (n)}]
     \end{aligned}
     \\
  &= [\bm{B}^{\prime (nn)}]^{-1}
     \bigl(
       [\widetilde{\bm{Q}}^{(n)}]
       - [\bm{B}^{\prime (nm)}] [\bm{V}^{2 (m)}]
       - [\bm{G}^{\prime \prime (nm)}] [\widetilde{\bm{\delta}}^{\prime (m)}]
       - [\bm{G}^{\prime \prime (nn)}] [\widetilde{\bm{\delta}}^{\prime (n)}]
     \bigr)
\end{split}
\end{equation}
\end{document}

I also removed all \big instructions (which should be either \bigl or \bigr, however) and made bold only the base. It's better to use the bm package that provides \bm (\boldsymbol is turned into a synonym, but \bm is easier to type).

enter image description here

  • Random note: nesting aligned within split was my second idea - but I got wrong alignment of the aligned block relative to the = sign. Your image shows it correct, so I investigated: compiling with TeX Live 2016 everything looks correct, compiling on ShareLaTeX is where I saw the alignment trouble: this image shows an overlay; red: with alignat, same output on ShareLaTeX and TeX Live, blue: aligned inside split, fine on TeX Live, but with broken outer alignment of the aligned block on ShareLaTeX as seen in the picture. – greyshade May 25 '17 at 7:51
  • @greyshade amsmath had an update not too long ago fixing wrong spacing before \begin{aligned} (see p. 4 in amsmath documentation). This can be fixed by using \!\begin{aligned} for old version, as this "fix" will yield the same output with the new version as well. – sodd May 25 '17 at 9:20
  • @hooy thanks for pointing out the update to aligned in amsmath! You are of course correct on how to fix the issue. (And for completeness: on 2017-05-25 ShareLaTeX seems to be using TeX Live 2014 and loads Package: amsmath 2013/01/14 v2.14 AMS math features - i.e. indeed before the v2.16a with the change) – greyshade May 25 '17 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.