# Writing an equation with two domains? [duplicate]

How do I write the following in LaTeX:

• Do you mean how to typeset it in LaTeX? – LaTeXereXeTaL Aug 12 at 0:20
• @LaTeXereXeTaL, no, I mean how can I write above equation in Latex? I unable to find the name in google – aan Aug 12 at 0:26
• Yes, that is what typesetting means. Check this answer, tex.stackexchange.com/a/551312/218142, which answers a very similar question. Does that help? – LaTeXereXeTaL Aug 12 at 0:28
• The best way to achieve this is with the amsmath package, and then use a \begin{cases} environment. The linked answer by LaTeXereXeTaL uses the cases package, which in this instance I think amsmath is the more advisable package. – oliversm Aug 12 at 0:46

As @Mico and @oliversm pointed out, there are two basic ways to do this.

Solution 1: using the cases package

\documentclass{article}
\usepackage{cases}

\begin{document}
\begin{numcases}{f(x)=}
x, & $$x \geq 0$$ \nonumber \\
0, & $$x < 0$$   \nonumber
\end{numcases}
\end{document}


Solution 2: using the cases environment of the amsmath package.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
$f(x) = \begin{cases} x, & x \geq 0 \\ 0, & x < 0 \end{cases}$
\end{document}


Both give the same result, although the use of the cases package seems to typeset the result a bit lower on the page than using the amsmath cases environment. Personally, I like the former because you don't have to remember to go into display mode before. Choose the one you prefer.

• I'd lean more towards amsmath over cases. Having to wrap it in a math mode is a feature, not a bug, since it allows you to use the same technique whether it's in a plain display math or in a numbered equation. – Don Hosek Aug 12 at 3:10
• @DonHosek I appreciate the advice! – LaTeXereXeTaL Aug 12 at 3:48

Found it, using cases

\documentclass{article}
\usepackage{cases}

\begin{document}

\begin{numcases}{f(x)=}
x, \: \: \: \: x \geq 0                           \\
0, \: \: \: \: x < 0
\end{numcases}

\end{document}

• @Mico, it said missing $inserted – aan Aug 12 at 1:29 • Your code does not reproduce the screenshot you posted earlier. – Mico Aug 12 at 1:29 • Please give \documentclass{article} \usepackage{amsmath} \begin{document}$ f(x) = \begin{cases} x, & x \geq 0 \\ 0, & x < 0 \end{cases} \$ \end{document} a shot. – Mico Aug 12 at 1:32