5

Hi, I want to write this equation in latex. I've write the following lines but there is no space between "j" and "and". Please tell me how to fix it. Thanks.

  \begin{align}
    Y_{ij} = \left\{\begin{array}{lr}
        \sum_{k \sim i}y_{ij}, & \text{if } i = j,\\
        {-y_{ij}}, & \text{if } i \ne j   \text{and } i \sim j,\\
        0, & \text{otherwise.}
        \end{array}
  \end{align}
2
  • 2
    Welcome to TeX SX! Write \text{ and }, not \text{and }. An observation: you have the cases environment which is simpler to type than \left\{\begin{array}{lr}...
    – Bernard
    Nov 26, 2019 at 23:48
  • You're missing the \right. to close the \left\{. I agreed with @Bernard, the cases environment would be simplier. Nov 27, 2019 at 1:01

3 Answers 3

9

You can have a simpler typing with the dcases* environment from mathtools: The d in the name of the environment means it will typed in \displaystyle and the star means the second column will be in text mode:

\usepackage{mathtools}
...........
 \begin{align}
    Y_{ij} = \begin{dcases*}
        \sum_{k \sim i}y_{ij}, & if $ i = j $,\\
        {-y_{ij}}, & if $ i \ne j $ and $ i \sim j $,\\
        0, & otherwise. 
        \end{dcases*}
  \end{align}

enter image description here

8

You can use the cases* environment from mathtools package which loads amsmath internally. It enables you to write in normal mode in the right column, so you don't worry about spacing between words.

\documentclass{article}
\usepackage{mathtools}
\begin{document}

\begin{equation}
Y_{ij} = \begin{cases*}
  \sum_{k\sim i}y_{ij}, & if $i = j$,\\
  -y_{ij},              & if $i \ne j$ and $i \sim j$,\\
  0,                    & otherwise.
\end{cases*}
\end{equation}

\end{document}

enter image description here

0

Adding one space should do the job, as well as a few other modifications.

\begin{align}
    Y_{ij} = \Bigg\{
        \begin{array}{ll}
        \sum_{k \sim i}y_{ij}, & \text{if } i = j,\\
        -y_{ij}, & \text{if } i \ne j \text{ and } i \sim j,\\
        0, & \text{otherwise.}
        \end{array}
\end{align}

enter image description here

2
  • 2
    Writing \\text instead of \text cannot be correct; did you maybe intend to suggest replacing \text{and } with \text{ and }? To make your code compilable, it's necessary to add a \right. statement after \end{array}. (The OP's code lacks the \right. statement as well.) Furthermore, you may want to change the column specification from lr to ll, get rid of the unnecessary curly braces around -y_{ij}, and use an equation environment instead of an align environment.
    – Mico
    Nov 27, 2019 at 5:18
  • 1
    ...now there's an additional space after and (one inside the \text and the other a control space \ ). Additionally, the left brace is too small compared to the 3-line construction. It's better to use cases (or similar here).
    – Werner
    Nov 27, 2019 at 5:39

You must log in to answer this question.

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