1

getting error in this equation

\begin{equation*}
r =
\left\{
\begin{aligned}
& a_p  \text{if }  \sum\limits_{p=1}^L a_p   &>&  \sum\limits_{q=1}^s a_q   \\
& a_q  \text{if }  \sum\limits_{p=1}^L a_p   &<&  \sum\limits_{q=1}^s a_q  
\end{aligned}
\end{equation*}
Peter Grill
  • 223,288
poorna
  • 91

1 Answers1

1

You can't let \left and \right span an alignment & naturally. You need to break them using a \left-\right. and \left.-\right pair, together with the optional \vphantoms to have similar vertical heights (as described in Left/Right across multi-line equation).

However, your problem is solved using either cases or dcases, depending on which you prefer:

enter image description here

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\[
  r = \begin{cases}
    a_p & \text{if } \sum_{p = 1}^L a_p > \sum_{q = 1}^s a_q \\
    a_q & \text{if } \sum_{p = 1}^L a_p < \sum_{q = 1}^s a_q
  \end{cases}
\]

\[
  r = \begin{dcases}
    a_p & \text{if } \sum_{p = 1}^L a_p > \sum_{q = 1}^s a_q \\
    a_q & \text{if } \sum_{p = 1}^L a_p < \sum_{q = 1}^s a_q
  \end{dcases}
\]

\end{document} 
Werner
  • 603,163
  • I am using \usepackage{amsmath} \usepackage{amssymb} packages.So if i use \usepackage{mathtools} again,it gives error saying that it already exists. How will I rectify this? – poorna Sep 12 '18 at 17:59
  • @poorna: I get no such error message. Since mathtools loads amsmath, what about \usepackage{mathtools,amssymb}? – Werner Sep 12 '18 at 18:12
  • how to allign eqn number here????? – poorna Sep 20 '18 at 18:35
  • @poorna: Can you provide some minimal code that one could examine in order to see what you're having problems with? – Werner Sep 21 '18 at 21:47
  • \begin{equation} r = \left{ \begin{aligned} & a_p \text{if } \sum\limits_{p=1}^L a_p &>& \sum\limits_{q=1}^s a_q \ & a_q \text{if } \sum\limits_{p=1}^L a_p &<& \sum\limits_{q=1}^s a_q
    \end{aligned} \end{equation
    }
    – poorna Sep 22 '18 at 10:23
  • the same code above but equation number is not aligned – poorna Sep 22 '18 at 10:23
  • @poorna: You're using equation* which doesn't print equation numbers. Here's a minimal example that replicates your output and doesn't use aligned but dcases (a \displaystyle equivalent of cases): code Where do you want the equation numbers? With each of the choices within the cases? For that you'll need to use the numcases environment from the cases package. – Werner Sep 23 '18 at 02:35