# Piecewise-defined functions

I'm trying to write these four piecewise-defined functions. I wrote this code:

\begin{equation}
\theta = \begin{cases}
\theta r + Se \left( \theta s - \theta r \right)  & Hp < 0 \\
\theta s                                                        & Hp \geq 0
\end{cases} \\
\end{equation}

\begin{equation}
Se =  \begin{cases}
\frac{1}{[1 + |\alpha Hp|^n]^m}  & Hp < 0 \\
1                                               & Hp \geq 0
\end{cases} \\
\end{equation}

\begin{equation}
C_m = \begin{cases}
\frac{\alpha m}{1 - m} \left( \theta s - \theta r \right) Se^{\frac{1}{m}} [1 - Se^{\frac{1}{m}} ]^m & Hp < 0 \\
0                                                                                                                                                & Hp \geq 0
\end{cases} \\
\end{equation}

\begin{equation}
K_r = \begin{cases}
Se^ l [1-[1- Se^{\frac{1}{m}}]^m] ^2 & Hp < 0 \\
1                                                       & Hp \geq 0
\end{cases}\\
\end{equation}


And I got this result: How is it possible to separate these four piecewise-defined functions?

• possible duplicate of How to write a function (piecewise) with bracket outside? – ChrisS Feb 17 '15 at 8:50
• You just need a single & – MaxNoe Feb 17 '15 at 8:54
• Welcome to TeX.SE. Thanks for including most of the required code. But, while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Feb 17 '15 at 14:57

## 2 Answers

Only use one ampersand, &.

See page 68 in lshort: https://tobi.oetiker.ch/lshort/lshort.pdf

Example:

\begin{equation*}
|x| = \begin{cases}
-x & \text{if } x < 0,\\
0 & \text{if } x = 0,\\
x & \text{if } x > 0.
\end{cases}
\end{equation*}


Produces: • I tend to prefer cases* which gives you the second cell in text mode so this line would be -x & if $x < 0$,\\. BTW, what font is that? – Manuel Feb 17 '15 at 9:33
• Yes, the starred version is useful. It's the Arev font: tug.dk/FontCatalogue/arev – Tommy L Feb 17 '15 at 10:31

Besides the use of cases as per Tommy L's answer, you could also:

1. Use an align environment since you have multiple consecutive equations,
2. Use a \makebox to obtain an alignment of the conditions. ## Notes:

• It is only necessary to apply the \MakeBox macro on one of the cases.
• I used the mathtools package as that incorporates some fixes on amsmath even though it doesn't make a difference in this particular case.

## Code:

\documentclass{article}
\usepackage{mathtools}
\usepackage{calc}

\newcommand*{\WidestExpression}{\frac{\alpha m}{1 - m} \left( \theta s - \theta r \right) Se^{\frac{1}{m}} [1 - Se^{\frac{1}{m}} ]^m}
\newcommand*{\MakeBox}{\makebox[\widthof{$\WidestExpression$}][l]{$#1$}}

\begin{document}
\begin{align*}
\theta &= \begin{cases}
\theta r + Se \left( \theta s - \theta r \right)  & Hp < 0 \\
\MakeBox{\theta s}                               & Hp \geq 0
\end{cases} \\
Se &=  \begin{cases}
\frac{1}{[1 + |\alpha Hp|^n]^m}                   & Hp < 0 \\
\MakeBox{1}                                       & Hp \geq 0
\end{cases} \\
C_m &= \begin{cases}
\WidestExpression                                 & Hp < 0 \\
0                                                 & Hp \geq 0
\end{cases} \\
K_r &= \begin{cases}
Se^ l [1-[1- Se^{\frac{1}{m}}]^m] ^2              & Hp < 0 \\
\MakeBox{1}                                       & Hp \geq 0
\end{cases}\\
\end{align*}
\end{document}