# Alignment in cases

I have this text in LaTeX:

$$sgn(x)= \begin{cases} -1 & \mbox{za podmínky } x>0\\ 0 & \mbox{za podmínky } x=0\\ 1 & \mbox{za podmínky } x>0 \end{cases}$$


But I would like to move the "0" and "1" more to the right. I need to move these numbers just below "1", not to have it below "-".

• You could add \phantom{-} in front of the 0 and 1 Jul 19 '13 at 23:04
• Not related to your question, but you should define a new command using \DeclareMathOperator{\sgn}{sgn} at the preamble such that you can use \sgn(x) instead of sgn(x). Jul 19 '13 at 23:46
• Jul 20 '13 at 1:02

Simplest is probably to use \phantom{-}1

Referencing my chat message from 2013-04-05, here is the definition of the cases environment that accepts one optional argument, the column specification of the left column. Thus writing \begin{cases}[r] the left column is set right-aligned.

This way you actually could even use siunitx’ table typsetting with the S column.

## Code

\documentclass{article}
\usepackage{amsmath,siunitx}
\DeclareMathOperator{\sgn}{sgn}
\makeatletter
\renewenvironment{cases}[1][l]{\matrix@check\cases\env@cases{#1}}{\endarray\right.}
\def\env@cases#1{%
\let\@ifnextchar\new@ifnextchar
\left\lbrace\def\arraystretch{1.2}%
\makeatother
\begin{document}
$\sgn(x)= \begin{cases}[c] -1 & \text{za podmínky } x>0\\ 0 & \text{za podmínky } x=0\\ 1 & \text{za podmínky } x>0 \end{cases}$

$\sgn(x)= \begin{cases}[r] -1 & \text{za podmínky } x>0\\ 0 & \text{za podmínky } x=0\\ 1 & \text{za podmínky } x>0 \end{cases}$

$\sgn(x)= \begin{cases}[{S[table-format=-1.0]}] -1 & \text{za podmínky } x>0\\ 0 & \text{za podmínky } x=0\\ 1 & \text{za podmínky } x>0 \end{cases}$
\end{document}


## Output

• This definition of cases is absolutely great (I am just tired of doing phantoms ;)). Please consider adding/sending your improvement to the amsmath package. Mar 15 '16 at 13:20

The cases environment of the amsmath package uses array with the column specification @{}l@{\quad}l@{}. Thus \multicolumn will work, e.g.:

\multicolumn{1}{@{}r@{\quad}}{...}


The alignment can also be influenced by \hfil and \hfill, because array or tabular are using \hfil to align and justify their column types l, c, and r.

\hfill 0 % puts 0 to the right


The following example shows the different methods:

\documentclass{article}

\usepackage{amsmath}

\begin{document}
$\begin{cases} \mbox{left/default} & \mbox{left/default} \\ \multicolumn{1}{@{}l@{\quad}}{\mbox{left}} & \multicolumn{1}{@{}l@{}} {\mbox{left}} \\ % \hfil \mbox{center} & \hfil \mbox{center} \\ \multicolumn{1}{@{}c@{\quad}}{\mbox{center}} & \multicolumn{1}{@{}c@{}} {\mbox{center}} \\ % \hfill \mbox{right} & \hfill \mbox{right} \\ \multicolumn{1}{@{}r@{\quad}}{\mbox{right}} & \multicolumn{1}{@{}r@{}} {\mbox{right}} \\ % \multicolumn{1}{@{}p{10em}@{\quad}}{Column type p \dotfill\newline with two lines \hrulefill} & \multicolumn{1}{@{}p{10em}@{}} {Column type p \dotfill\newline with two lines \hrulefill} \\ \end{cases}$
\end{document}


Applied to the case of the OP:

\documentclass{article}

\usepackage{amsmath}

\DeclareMathOperator{\sgn}{sgn}

\begin{document}
$\sgn(x)= \begin{cases} -1 & \mbox{za podmínky } x>0\\ \hfill 0 & \mbox{za podmínky } x=0\\ \hfill 1 & \mbox{za podmínky } x>0 \end{cases}$
\end{document}


• I've taken the liberty of editing your text to make its English a bit more idiomatic. I trust you're OK with that.
– Mico
Sep 14 '13 at 17:15
• @Mico: Thanks, of course I am OK with the corrections. I have also updated the image. Sep 14 '13 at 17:26
• Brilliant, just use \hfill for baby cases! Thanks. Apr 7 '19 at 2:48

Here is an alternative solution, which uses array for better alignment control:

\begin{align*}
\sgn(x)=\left\{
\begin{array}{lll}
-1& \mbox{za podmínky} & x>0\\
0 & \mbox{za podmínky} & x=0\\
1 & \mbox{za podmínky} & x>0
\end{array}\right.
\end{align*}

\begin{align*}
\sgn(x)=\left\{
\begin{array}{ccc}
-1& \mbox{za podmínky} & x>0\\
0 & \mbox{za podmínky} & x=0\\
1 & \mbox{za podmínky} & x>0
\end{array}\right.
\end{align*}

\begin{align*}
\sgn(x)=\left\{
\begin{array}{rrr}
-1& \mbox{za podmínky} & x>0\\
0 & \mbox{za podmínky} & x=0\\
1 & \mbox{za podmínky} & x>0
\end{array}\right.
\end{align*}


Result:

• @daleif: This old post got upvoted recently, which reminds me: why not make a centered dcases into mathtools? Something like \newcases{cdcases}{\quad}{% $\m@th\hfil\displaystyle{##}$\hfil}{$\m@th\displaystyle{##}$\hfil}{\lbrace}{.} That said, I think the package document should mention \newcases command. Nov 5 '13 at 13:21

For a more global take on this, you can adjust the alignment of cases to be right-left rather than the default (left-left). Here's how:

\documentclass{article}
\usepackage[utf8]{inputenc}% http://ctan.org/pkg/inputenc
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\makeatletter
\def\env@cases{%
\let\@ifnextchar\new@ifnextchar
\left\lbrace
\def\arraystretch{1.2}%
}
\makeatother
\DeclareMathOperator{\Sign}{sgn}

\begin{document}

$\Sign(x) = \begin{cases} -1 & \text{za podmínky } x > 0 \\ 0 & \text{za podmínky } x = 0 \\ 1 & \text{za podmínky } x > 0 \end{cases}$

\end{document}


You'll note that the alignment comes from the array column specification @{}l@{\quad}l@{}, which can be adjusted to suit your needs.

Just another simple approach.

\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage{amsmath}
\DeclareMathOperator{\sgn}{sgn}
\begin{document}
\abovedisplayskip=0pt\relax
\sgn(x)= \left\{ \begin{aligned} -1 & \text{ za podm\'inky } x>0\\ 0 & \text{ za podm\'inky } x=0\\ 1 & \text{ za podm\'inky } x<0 \end{aligned} \right.
\end{document}


• There is a typo, < should be changed to >! Sep 14 '13 at 13:03

Before considering the positions of $0$ and $-1$, one should use \cases typographically right:

\documentclass{article}
\pagestyle{empty}
\usepackage{amsmath}
\begin{document}
$$sgn(x)= \begin{cases} -1 & \mbox{za podmínky } x>0\\ 0 & \mbox{za podmínky } x=0\\ 1 & \mbox{za podmínky } x>0 \end{cases}$$
$$\mathrm{sgn}(x)= \begin{cases} -1\text{,} & \text{za podmínky x>0;}\\ 0\text{,} & \text{za podmínky x=0;}\\ 1\text{,} & \text{za podmínky  x>0.} \end{cases}$$

\end{document}