How do I write the following in LaTeX:
2 Answers
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.
- 3,594
-
3I'd lean more towards
amsmathovercases. 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 numberedequation. – Don Hosek Aug 12 '20 at 03:10 -
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}
- 2,663
-
-
-
4Please 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 '20 at 01:32


amsmathpackage, and then use a\begin{cases}environment. The linked answer by LaTeXereXeTaL uses thecasespackage, which in this instance I thinkamsmathis the more advisable package. – oliversm Aug 12 '20 at 00:46texdoc amsmathto bring up the user guide of theamsmathpackage, and study thecasesenvironment on page 9 of the document. – Mico Aug 12 '20 at 00:49