[Tex/LaTex] How to fit a math equation to the line width

amsmathmath-modewidth

I used the following two equations to implement a branch function:

\documentclass[conference]{IEEEtran}
\usepackage{amsmath}
\newcommand{\NC}{\mathrm{NC}}

\begin{document}

        In Case A, \\


    \begin{equation}
    \Pr\{\mathrm{NC}|\alpha\}= \left\{
    \begin{array}{ll}
          (1-p)^{n-1}(1-p+p(\alpha + \beta)^{2})^{n-1} & 0\leq \alpha \leq \beta \\
          (1-p)^{n-1}(1-p+4p\alpha\beta)^{n-1} & \beta\leq \alpha \leq \beta-1\\
          (1-p)^{n-1} (1-p(\alpha - \beta)^{2})^{n-1} & 1-\beta\leq \alpha \leq 1 \\

    \end{array} 
    \right.
    \end{equation} \\ 

    In Case B, \\

    \begin{equation} 
    \Pr\{\mathrm{NC}|\alpha\}= \left\{
    \begin{array}{ll}
          (1-p)^{n-1}(1-p+p(\alpha + \beta)^{2})^{n-1} & 0\leq \alpha \leq \beta \\
          (1-p)^{n-1}(1-p+4p\alpha\beta)^{n-1} & \beta\leq \alpha \leq \beta-1\\
          (1-p)^{n-1} (1-p(\alpha - \beta)^{2})^{n-1} & 1-\beta\leq \alpha \leq 1 \\
    \end{array} 
    \right.
    \end{equation}

\end{document}

But the equations exceeded the line width (9&10) or in other words the column words as seen here:

enter image description here

Best Answer

Don't use \\ for ending lines, except where specifically needed (tabular, array or similar environments) and never leave a blank line before an equation.

Narrow columns and cases don't go along well, so you have only one possibility: splitting the lines, one part with the value, one with the condition. More generous vertical space will help the reader in understanding what refers to what.

\documentclass[twocolumn]{article}
\usepackage{amsmath}

\newcommand{\NC}{\mathrm{NC}}

\begin{document}

\begin{equation}
\Pr\{\NC|\alpha\}=
\begin{cases}
e^{-2\lambda+\lambda(\alpha+\beta)^{2}} \\
  \qquad \text{for } 0\leq \alpha \leq 1-\beta \\[2ex]
e^{-2\lambda+4\lambda\alpha\beta} \\
  \qquad \text{for } 1-\beta\leq \alpha\leq \beta \\[2ex]
e^{-\lambda-\lambda(\alpha-\beta)^{2}} \\
  \qquad \text{for }\beta\leq \alpha\leq 1
\end{cases}
\end{equation}
If $0.5 \leq \beta \leq 1$:
\begin{equation}
\Pr\{\NC|\alpha\}=
\begin{cases}
e^{-2\lambda+\lambda(\alpha+\beta)^{2}} \\
  \qquad \text{for } 0\leq \alpha \leq \beta \\[2ex]
e^{-2\lambda+4\lambda\alpha\beta} \\
  \qquad \text{for } \beta\leq \alpha\leq 1-\beta \\[2ex]
e^{-\lambda-\lambda(\alpha-\beta)^{2}} \\
  \qquad \text{for } \beta-1\leq \alpha\leq 1
\end{cases}
\end{equation}

\end{document}

enter image description here

The other set of equations poses more problems, because of the width, so with the standard page parameters the equation number will be shifted: don't worry about it.

\documentclass[twocolumn]{article}
\usepackage{amsmath}

\newcommand{\NC}{\mathrm{NC}}

\begin{document}

In Case A,
\begin{equation}
\Pr\{\NC|\alpha\}=
\begin{cases}
(1-p)^{n-1}(1-p+p(\alpha + \beta)^{2})^{n-1}\\
  \qquad \text{for } 0\leq \alpha \leq \beta \\[2ex]
(1-p)^{n-1}(1-p+4p\alpha\beta)^{n-1} \\
  \qquad \text{for } \beta\leq \alpha \leq \beta-1 \\[2ex]
(1-p)^{n-1} (1-p(\alpha - \beta)^{2})^{n-1} \\
  \qquad \text{for } 1-\beta\leq \alpha \leq 1
\end{cases}
\end{equation}
In Case B,
\begin{equation}
\Pr\{\mathrm{NC}|\alpha\}=
\begin{cases}
(1-p)^{n-1}(1-p+p(\alpha + \beta)^{2})^{n-1} \\
   \qquad \text{for } 0\leq \alpha \leq \beta \\[2ex]
(1-p)^{n-1}(1-p+4p\alpha\beta)^{n-1} \\
  \qquad \text{for } \beta\leq \alpha \leq \beta-1 \\[2ex]
(1-p)^{n-1} (1-p(\alpha - \beta)^{2})^{n-1} \\
  \qquad \text{for } 1-\beta\leq \alpha \leq 1
\end{cases}
\end{equation}

enter image description here