8

This question already has an answer here:

I am attempting to write out the basic process for finding the absolute value of some number.

In ASCII, this is what I am attempting to write.

|X| = {
        x  if x > 0
        0  if x = 0
        -x if x < 0
      }

This is what I have so far.

\begin{equation}
\left|x\right| = \biggl\{ x\ if\ x > 0 \biggr\}
\end{equation}

I cannot figure out how to add the vertical spacing to allow the other two lines.

marked as duplicate by egreg, Fran, Przemysław Scherwentke, Guido, Andrew Swann Oct 22 '13 at 6:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Welcome to the site! have you looked at the cases environment? have you seen How to write conditional equations with one-sided curly brackets – cmhughes Oct 21 '13 at 16:54
  • This is not a duplicate. The OP ask for a two-sided curly brackets. – Fran Oct 21 '13 at 18:35
  • I've never seen the right brace in cases like this. – egreg Oct 21 '13 at 22:53
  • It is a duplicate, seeing what answer has been accepted. – egreg Oct 21 '13 at 23:31
  • Then I take that back, it is a duplicate – Fran Oct 21 '13 at 23:54
9

Option 1 (recommended)

left aligned

\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage{mathtools}
\begin{document}
\abovedisplayskip=0pt\relax
\[
\lvert x \rvert =
\begin{cases}
x & \text{if } x>0\\
0 & \text{if } x=0\\
-x& \text{if } x<0
\end{cases}
\]
\end{document}

enter image description here

Option 2 (just for fun)

right aligned

\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage{mathtools}
\begin{document}
\abovedisplayskip=0pt\relax
\[
\lvert x \rvert =
\left\{
\!
\begin{aligned}
x & \text{ if } x>0\\
0 & \text{ if } x=0\\
-x& \text{ if } x<0
\end{aligned}
\right.
\]
\end{document}

enter image description here

Important Notes

standalone class and \abovedisplayskip=0pt are settings for my own purpose to create a standalone and tight output. You should not use it for your production unless your objective is the same as mine.

  • 2
    There's no need to drop use of the cases environment just because you might want to typeset the contents of the first column flush-right. Just write \hill x and \hfill 0 instead of x and 0. – Mico Oct 21 '13 at 17:26
  • @Mico: Yes. It is a just-for-fun option. Thanks. – kiss my armpit Oct 21 '13 at 17:30
  • 1
    A real disadvantage of using the aligned environment (at least in the way you've implemented it in your example code) instead of the cases environment for the purpose at hand is that you get inferior horizontal spacing between the first and second columns. – Mico Oct 21 '13 at 17:36
  • 2
    Please, make clear in your answer that \abovedisplayskip=0pt is a setting just for the examples. – egreg Oct 21 '13 at 22:48
0

Using the beta version of my tabstackengine package presented at Writing a table with equally spaced columns, based on the widest column, I can give you a number of configurable options on the appearance of the output. First, I give it with the package default spacings. Then I show how the horizontal gap can be increased in the stack, and finally how the interline spacing can be increased.

\documentclass{article}
\usepackage{tabstackengine}
\begin{document}
\[
\vert X\vert = \left\{
\alignVectorstack{
&x &\mathrm{if~} & x > 0\\
&0 &\mathrm{if~} & x = 0\\
&-x&\mathrm{if~} & x < 0
}
\right.
\]
\setstackaligngap{3em}
\[
\vert X\vert = \left\{
\alignVectorstack{
&x &\mathrm{if~} & x > 0\\
&0 &\mathrm{if~} & x = 0\\
&-x&\mathrm{if~} & x < 0
}
\right.
\]
\setstackgap{L}{1.4\baselineskip}
\[
\vert X\vert = \left\{
\alignVectorstack{
&x &\mathrm{if~} & x > 0\\
&0 &\mathrm{if~} & x = 0\\
&-x&\mathrm{if~} & x < 0
}
\right.
\]
\end{document}

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.