242

I want to write a conditional expression such as the following.

enter image description here

What is the best way to express such conditional expressions in Latex?

MattAllegro
  • 1,546
highBandWidth
  • 2,533
  • 2
  • 15
  • 6

2 Answers2

305

I think this is a job for cases from the amsmath package

enter image description here

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\[
    f(x)= 
\begin{cases}
    \frac{x^2-x}{x},& \text{if } x\geq 1\\
    0,              & \text{otherwise}
\end{cases}
\]
\end{document}

or if you would prefer a displaystyle fraction, then you could use dcases from the mathtools package, which extends (and loads) the amsmath package.

enter image description here

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\[
    f(x)= 
\begin{dcases}
    \frac{x^2-x}{x},& \text{if } x\geq 1\\
    0,              & \text{otherwise}
\end{dcases}
\]
\end{document}
cmhughes
  • 100,947
50

Just for the sake of completeness (i.e. environments where amsmath may not be available): There is a pseudo-parenthesis . that can be used to terminate an opening parenthesis:

\documentclass{standalone}

\begin{document}

$\left{ \begin{array}{ c l } \frac{x^2 - x}{2} & \quad \textrm{if } x \geq 1 \ 0 & \quad \textrm{otherwise} \end{array} \right.$

\end{document}

Output:

enter image description here

Werner
  • 603,163
krlmlr
  • 12,530
  • 11
    You should expand this answer to show how to use this to produce the output in the original image. – Peter Grill Mar 10 '12 at 01:04
  • 5
    @PeterGrill: Well, there are ways, but cases and dcases are much much more suitable for this task. Are there conditions where these environments are not available? – krlmlr Mar 10 '12 at 05:48
  • 3
    I actually like your answer better. – 0rkan Sep 25 '15 at 03:09
  • I like this answer for its flexibility. It shows how to create a single-sided brace (or any other grouping symbol) for applications where cases isn't suitable. – drmuelr Oct 13 '18 at 05:31
  • @krlmlr I have found environments where I don't have access to the amsmath package, so expanding this to perform what the question asked for would certainly help me! – Connor McCormick Jan 25 '21 at 16:26