23

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}
$$

sgn

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 "-".

Moriambar
  • 11,466
goLK
  • 793

7 Answers7

25

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}%
  \array{@{}#1@{\quad}l@{}}}
\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

enter image description here

Moriambar
  • 11,466
Qrrbrbirlbel
  • 119,821
22

Simplest is probably to use \phantom{-}1

David Carlisle
  • 757,742
9

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}

Result

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}

Result

Moriambar
  • 11,466
Heiko Oberdiek
  • 271,626
4

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:
enter image description here

David Carlisle
  • 757,742
Francis
  • 6,183
  • 1
    @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. – Francis Nov 05 '13 at 13:21
3

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:

enter image description here

\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}%
  \array{@{}r@{\quad}l@{}}% Changed from \array{@{}l@{\quad}l@{}}
}
\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.

Moriambar
  • 11,466
Werner
  • 603,163
2

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}

enter image description here

Moriambar
  • 11,466
-1

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}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149