Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to align something under cases as follows:

value1                    if condition
value2  line1ofvalue2...  otherwise
        line2ofvalue2..
        line3ofvalue2.

First, there are only 2 conditions (each one for one value), so I want if condition and otherwise are left adjusted. Then as my value2 is a long, I need to split it into 3 lines, so I want these 3 lines to be left adjusted.

Does anyone know how to do this? Thank you very much

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

The array environment provides a very similar layout and typesetting to the amsmath package cases environment. In fact, amsmath defines cases exactly as an array with some stretch (an \arraystretch of 1.2) and a specific column alignment (@{}ll@{}). Consider the following minimal example displaying the two different styles:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\noindent Original \texttt{cases} example:
\[
X=%
  \begin{cases}
    0& \text{if $r-j$ is odd},\\
    r!\,(-1)^{(r-j)/2}& \text{if $r-j$ is even}.
  \end{cases}
\]

\noindent Using the \texttt{array} environment:
\[
\renewcommand{\arraystretch}{1.2}%
X=\left\{%
  \begin{array}{@{}ll@{}}
    0& \text{if $r-j$ is odd},\\
    r!\,(-1)^{(r-j)/2}& \text{if $r-j$ is even}.
  \end{array}
  \right.
\]
\end{document}

Array vs cases

Therefore, using the array environment, one could attempt:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\noindent Requested environment using \texttt{array}:
\[
\renewcommand{\arraystretch}{1.2}%
X=\left\{%
  \begin{array}{@{}lll@{}}
    0& & \text{if $r-j$ is odd},\\
    k& +7& \text{if $r-j$ is even}. \\
    & +1+2i& \\
    & \binom{3}{n}
  \end{array}
  \right.
\]
\end{document}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Array environment similar to cases (with 3 columns)

The gap between the first two left-aligned columns can also be adjusted (using @{}l@{}ll@{}, say) if needed. The advantage of this approach is flexibility in terms of the array environment, while still retaining the visual equivalence with the cases environment; that is, a user-defined cases environment.

share|improve this answer
    
Thanks for your comment, what is the use of % in the \left\{%? –  SoftTimur Aug 9 '11 at 2:37
    
I almost use it out of habit, but it's best to read the short and long answer to this here: What is the use of percent signs at the end of lines –  Werner Aug 9 '11 at 2:44
add comment

Here's an extension of the amsmath cases environment. There's a new optional argument for customizing the cases columns. Without argument, it work like the original cases.

\makeatletter
\renewcommand\env@cases[1][@{}l@{\quad}l@{}]{%
  \let\@ifnextchar\new@ifnextchar
  \left\lbrace
  \def\arraystretch{1.2}%
  \array{#1}%
}
\makeatother

The original definition in amsmath.sty contains @{}l@{\quad}l@{}, which we replaced by #1. Now you can use all features of array column specifications.

Complete example with usage:

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\renewcommand\env@cases[1][@{}l@{\quad}l@{}]{%
  \let\@ifnextchar\new@ifnextchar
  \left\lbrace
  \def\arraystretch{1.2}%
  \array{#1}%
}
\makeatother
\begin{document}
\[
\begin{cases}
  value1 & if condition \\
  value2 & otherwise
\end{cases}
\]
\[
\begin{cases}[@{}lp{3cm}l@{}]
  value1 & & if condition \\
  value2 & line1ofvalue2 \newline
           line2ofvalue2 \newline
           line3ofvalue2          & otherwise
\end{cases}
\]
\end{document}
share|improve this answer
add comment

Is this what you are looking for?

\documentclass{article}
\usepackage[fleqn]{amsmath}
\begin{document}
\newcommand{\Phantom}{\phantom{value2}}%
\begin{align*}
f(x) = \begin{cases}
value1& condition1 \\
value2 \text{ line1ofvalue2}& condition2\\
\Phantom \text{ line2ofvalue2}\\
\Phantom \text{ line3ofvalue2}
\end{cases}
\end{align*}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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