22

I want to align equations (using the align environment from the amsmath package) inside matching \left( and \right) commands. For example:

\documentclass[a4paper,12pt]{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
    a \left( b &= c \right)\\
    d \left( e &= f \right)
\end{align}

\end{document}

But that code gives this error:

Extra }, or forgotten \right.

The error disappears when I remove the delimiters. Is there a workaround for this?

Werner
  • 603,163

3 Answers3

19

You cannot split \left...\right across alignment tabs. One solution is to use the \big-delimiters (which don't require pairwise usage):

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath

\begin{document}

\begin{align}
  a \bigl( b &= c \biggr) \\
  d \Bigl( e &= f \Biggr)
\end{align}

\end{document}

The above example is just to illustrate some delimiter sizes you can choose from. See section 4.14.1 Delimiter sizes of the amsmath user guide for more options:

enter image description here

Alternatively, one can adjust the alignment manually and avoid using & altogether. However, the above option is far easier to manage.

Werner
  • 603,163
  • 3
    This. Plus: never use \left and \right as long as you don't need to be bigger than Bigger – yo' Feb 14 '14 at 18:15
3

You can also accompany (i) \left( with \right. or (ii) \left. with \right). In other words,

\documentclass[a4paper,12pt]{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
    a \left( b \right. &=  \left. c \right)\\
    d \left( e \right. &=  \left. f \right)
\end{align}

\end{document}

In that way, you will not obtain the error that you posted.

Werner
  • 603,163
  • 3
    Hi, welcome. The (potential) drawback of this is that it doesn't work well if b and c has different heights (try replacing c with \frac{a}{c}). You'll get different size parenthesis, unless you e.g. add a \vphantom{\frac{a}{c}} on the left side. – Torbjørn T. May 10 '17 at 18:34
0

You can use an incredible useful workaround from the mathtools-manual, p.29, that even includes line-breaks:

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

MWE

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

\begin{document} \begin{equation} \begin{alignedat}{2} x &= \brackets{a &&+ \int_a^b x ,\mathrm{d}x}\ % auto size &= \brackets{\text{loooong} &&+ (b^2 - a^2)}\ &= \brackets[\bigg]{\text{loooong} &&+ (b^2 - a^2)}\ % manual size &= \brackets[\bigg]{\text{loooong} &&\&&&+ (b^2 - a^2)} \end{alignedat} \end{equation} \end{document}

image

Note: If you look at the pdf documentation for mathtools, on page 29 the symbol that comes after \catcode appears to be an apostrophe. But looking at the .dtx source code the symbol is actually a backtick.

Suuuehgi
  • 887
  • 4
  • 18