Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm writing a paper and I have inserted a piecewise function into my tex-code. My problem is that the piecewise function is very tightly packed. How could I stretch the bracket and get more space between the formulas? See code and result below:

$$
\displaystyle{
P(Y_i = j) = \left\{
        \begin{array}{ll}
            \frac{1}{1+\sum_{k=1}^{K-1}e^{\beta_k\cdot x_i}} & \quad k=K \\
            \frac{e^{\beta_j\cdot x_i}}{1+\sum_{k=1}^{K-1}e^{\beta_k\cdot x_i}} & \quad 1 \leq k \leq K-1
        \end{array}
    \right.,
    }
$$

enter image description here

share|improve this question
3  
I think that what you are looking for is the cases environment, as described in How to write conditional equations with one-sided curly brackets –  tohecz Dec 11 '13 at 13:15
    
And also, do you perhaps mean $P(Y_{i=j})$? I've just never seen notation such as it is currently (with my limited exposure). –  Sean Allred Dec 11 '13 at 13:26
add comment

3 Answers

up vote 10 down vote accepted

Don't use $$ for display math.

\displaystyle is not needed.

Option -1:

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

\[
P(Y_i = j) = \left\{
        \begin{array}{ll}
            \frac{1}{1+\sum_{k=1}^{K-1}e^{\beta_k\cdot x_i}} & \quad k=K \\[1em]
            \frac{e^{\beta_j\cdot x_i}}{1+\sum_{k=1}^{K-1}e^{\beta_k\cdot x_i}} & \quad 1 \leq k \leq K-1
        \end{array}
    \right.,
\]
\end{document}

enter image description here

Option - 2

You can use cases.

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

\[
P(Y_i = j) = \begin{cases}
            \frac{1}{1+\sum_{k=1}^{K-1}e^{\beta_k\cdot x_i}} & \quad k=K \\[1em]   %%% <--- here
            \frac{e^{\beta_j\cdot x_i}}{1+\sum_{k=1}^{K-1}e^{\beta_k\cdot x_i}} & \quad 1 \leq k \leq K-1
        \end{cases}
\]
\end{document}

In either case, you can use \\[<dimen>] to change the vertical separation.

Beautification

To make your sums to look less cramped, you can use \limits as in

\sum\limits_{k=1}^{K-1}

Code:

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

\[
P(Y_i = j) = \begin{cases}
            \frac{1}{1+\sum\limits_{k=1}^{K-1}e^{\beta_k\cdot x_i}} & \quad k=K \\[2em]
            \frac{e^{\beta_j\cdot x_i}}{1+\sum\limits_{k=1}^{K-1}e^{\beta_k\cdot x_i}} & \quad 1 \leq k \leq K-1
        \end{cases}
\]
\end{document}

enter image description here

share|improve this answer
    
+1 Thank you very much! :) –  jjepsuomi Dec 11 '13 at 13:16
    
ehm cases ehm –  tohecz Dec 11 '13 at 13:16
1  
if you are loading amsmath anyway you could use the cases environment which is specifically for this use. –  David Carlisle Dec 11 '13 at 13:16
    
@tohecz I didn't finish yet. Options are on way :-) –  Harish Kumar Dec 11 '13 at 13:17
    
Okay :) thank you! –  jjepsuomi Dec 11 '13 at 13:17
show 2 more comments

I had no idea that amsmath had such a useful redefinition, so that should be the correct answer (after use of cases). However, for completeness (or if you want more space) you have a few options:

  • reformulate your terms to allow for more vertical leg-room
  • modify \arraystretch to a desired scale (but will cause potentially awkward space on top)
  • use a strut, as in the example below:

    \documentclass{article}
    \usepackage{array}
    
    %\renewcommand\arraystretch{4}
    
    \begin{document}
    \[
    P(Y_i = j) = \left\{
      \begin{array}{>{\displaystyle}ll}
        \biggl(1+\sum_{k=1}^{K-1}e^{\beta_k\cdot x_i}\biggr)^{-1}
        & \quad k=K \\
        \biggl(1+\sum_{k=1}^{K-1}e^{\beta_k\cdot x_i}\biggr)^{-1}
        e^{\beta_j\cdot x_i}
        & \quad 1 \leq k \leq K-1
    
        \rule{0pt}{8ex} % called a 'strut' -- a vertical rule of nil width
      \end{array}
      \right.,
    \]
    \end{document}
    

    output

share|improve this answer
1  
No, this is wrong. The parentheses are too large. Try \biggl(...\biggr) instead of \left(...\right), please. After all, why \displaystyle when `\textstyle would fit there much better? Anyways, +1 for getting rid of the fractions. –  tohecz Dec 11 '13 at 13:25
1  
@tohecz Ah, yes - \left and \right don't take the limits into account very well... And personally, while I haven't much of a leg to stand on as for conventions, if you're going to have a large cases like this, it should be \displayed, not so cramped as in \textstyle. Just personal preference probably prejudiced by handwritten math :) –  Sean Allred Dec 11 '13 at 13:29
    
+1 Thank you for your help guys! :) –  jjepsuomi Dec 12 '13 at 6:00
add comment

The dcases environment by »mathtools« from the »mh« bundle seems to be quite handy here.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}  % loads »amsmath«

\begin{document}
  \[
    P(Y_i=j)=
    \begin{dcases}
      \frac{1}{1+\sum\limits_{k=1}^{K-1}e^{\beta_k\cdot x_i}} & \quad k=K \\
      \frac{e^{\beta_j\cdot x_i}}{1+\sum\limits_{k=1}^{K-1}e^{\beta_k\cdot x_i}} & \quad 1 \leq k \leq K-1
    \end{dcases}
  \]
\end{document}

enter image description here

share|improve this answer
    
+1 Thank you for your help! :) –  jjepsuomi Dec 12 '13 at 6:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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