0

How do I write the following in LaTeX:

enter image description here

oliversm
  • 2,717
aan
  • 2,663

2 Answers2

7

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}

Compiled output

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
    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 '20 at 03:10
  • @DonHosek I appreciate the advice! – LaTeXereXeTaL Aug 12 '20 at 03:48
0

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}

aan
  • 2,663
  • @Mico, it said missing $ inserted – aan Aug 12 '20 at 01:29
  • Your code does not reproduce the screenshot you posted earlier. – Mico Aug 12 '20 at 01:29
  • 4
    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 '20 at 01:32