How to get more space in piecewise function on LaTeX?
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}
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 sum
s 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}
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}
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}