6

I have a weird problem with the Align environment in combination with brackets spanning more than 1 line. When I add alignment markers (&) to my equation in the Align environment I suddenly get an error saying that I have an extra }.

The minimal example that reproduces the error looks like this:

\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}

\begin{document}
    \begin{align}
    J      =& 2  \left[3x \right.  \nonumber  \\
    \left. +& 4  \right]
    \end{align}
\end{document}

If i take out the & it works. If I take out the brackets it also works. Can anyone explain what is going on and how I can overcome this issue?

For completeness, the actual equation looks like this:

\begin{align}
 J=E-\Delta P V =& \gamma\int_{-\pi}^{\pi}\int_0^{r_0}\left[\sqrt{r^2+r^2 \partial_r z^2 + \partial_\phi z^2}-r \cos\theta_Y \right. \nonumber  \\
\left. + & \,\frac{\rho g}{\gamma} z r \left(\frac{z}{2}\cos\alpha-r \sin \alpha \cos\phi\right)-\Delta P r z  \right] dr d\phi
\end{align}
6
  • You can't start \left in an alignment cell and have \right in another one. In the example there's no need of \left and \right, by the way.
    – egreg
    Jul 7, 2014 at 7:59
  • @egreg I know that there is no need for the \left \right here, but this is a minimal example to reproduce the issue. The actual equation contains several larger terms
    – Michiel
    Jul 7, 2014 at 8:01
  • I remarked it because it's frequent to see \left and \right where they serve no purpose. Can you add a sample of the real thing?
    – egreg
    Jul 7, 2014 at 8:04
  • The actual equation looks like shown in the edit
    – Michiel
    Jul 7, 2014 at 8:05
  • @Michiel Please observe the correct position of the pair & and =. Jul 7, 2014 at 8:09

3 Answers 3

5

Is that what you want?

% arara: pdflatex

\documentclass{article}
\usepackage{amsmath}

\begin{document}
    \begin{align}
    J &= 2 \left[3x \right. \nonumber \\
     &+ \left. 4  \right]
    \end{align}
\end{document}

enter image description here

The problem in your MWE was that you put a & between your left and right delimiter. Instead of the automatic solution of \left[ and \right] I would recommend a manual choice for most cases (especially here, where the bracket from first line could get another automatic sizing than the bracket from the second line). In the following MWE, you can see how to use \bigl[/\bigr] as an example. In this very case, you could just use [ ], as you do not need enlarged brackets.

% arara: pdflatex

\documentclass{article}
\usepackage{amsmath}

\begin{document}
    \begin{align}
    J &= 2 \bigl[3x \nonumber \\
     &\quad+ 4\bigr]
    \end{align}
\end{document}

And here is your real example:

% arara: pdflatex

\documentclass{article}
\usepackage{amsmath}
\newcommand{\der}{\,\mathrm{d}}

\begin{document}
\begin{align}
J&=E-\Delta PV\nonumber\\
&=\gamma\int_{-\pi}^{\pi}\int_0^{r_0}\biggl[\sqrt{r^2+r^2 \partial_r z^2 + \partial_\phi z^2}-r \cos\theta_Y \nonumber  \\
&\phantom{{}=\gamma\int_{-\pi}^{\pi}\int_0^{r_0}\biggl[}+\frac{\rho g}{\gamma} zr \biggl(\frac{z}{2}\cos\alpha-r \sin \alpha \cos\phi\biggr)-\Delta Prz\biggr] \der r\der\phi
\end{align}
\end{document}

enter image description here

1
  • 1
    This is indeed what I was looking for. Didn't know that the & inside delimiters was an issue. Thanks!
    – Michiel
    Jul 7, 2014 at 8:05
5

For a split equation like that, I would use multline rather than align:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{multline}
J = E-\Delta P V =
\gamma\int_{-\pi}^{\pi}\int_0^{r_0}\biggl[
  \sqrt{r^2+r^2 \partial_r z^2 + \partial_\phi z^2} - r \cos\theta_Y +{}\\
  \frac{\rho g}{\gamma} z r 
    \left(\frac{z}{2}\cos\alpha- r \sin \alpha \cos\phi\right) -
    \Delta P r z  
\biggr]\,dr \,d\phi
\end{multline}
\end{document}

enter image description here

Note the explicit sizing commands \biggl and \biggr that are unavoidable if the delimiters are in different parts of a display (including different cells in a single row of align).

If you prefer a three stage display, use split:

\documentclass{article}
\usepackage[tbtags]{amsmath}
\begin{document}

\begin{equation}
\begin{split}
J &= E-\Delta P V\\
&= \gamma\int_{-\pi}^{\pi}\int_0^{r_0}\biggl[
     \sqrt{r^2+r^2 \partial_r z^2 + \partial_\phi z^2} - r \cos\theta_Y +{}\\
&\hspace{6em}\frac{\rho g}{\gamma} z r
     \left(\frac{z}{2}\cos\alpha- r \sin \alpha \cos\phi\right) -
     \Delta P r z
\biggr]\,dr \,d\phi
\end{split}
\end{equation}

\end{document}

The \hspace{6em} bit has been computed by eye; with a \hphantom you can add the precise space for aligning to something in the line above, although it doesn't seem necessary.

enter image description here

1
  • This also looks nice, but I prefer to have control over the alignment
    – Michiel
    Jul 7, 2014 at 13:22
1
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}

\begin{document}
    \begin{align}
    J      &= 2  \left[3x \right.  \nonumber  \\
     & \left.{}+ 4  \right]
    \end{align}
\end{document}
  1. In your example the pair \left \right was separated by &, not being a group.

  2. Please observe the switch of & and =.

  3. Using the group left and right is easy, but not recommended. In particular the effective sizes of parentheses may be different in different lines.

  4. I would rather add, e.g., \quad before + in the second line.

4
  • Bad idea, may end up with different sizes depending on the material. Manual scaling is better.
    – daleif
    Jul 7, 2014 at 8:13
  • @daleif Certainly, but the other mistakes were more important for me. Jul 7, 2014 at 8:15
  • My point is just that others will read this when searching the archives and ought to be told that it is not a good solution in general.
    – daleif
    Jul 7, 2014 at 8:27
  • 1
    @daleif I have just added, with an additional remark. Jul 7, 2014 at 8:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .