The code I used to write
is this one
$$
X(m,n)=
\begin{cases}
x(n),\\
x(n-1)\\
x(n-1)
\end{cases}
$$
But I don't know how to write this one
Also, what if I want to write this
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this community\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
X(m,n) = \left\{\begin{array}{lr}
x(n), & \text{for } 0\leq n\leq 1\\
x(n-1), & \text{for } 0\leq n\leq 1\\
x(n-1), & \text{for } 0\leq n\leq 1
\end{array}\right\} = xy
\]
\end{document}
If you want two conditions on different lines, can use a \multirow
for the first column:
\documentclass{article}
\usepackage{amsmath}
\usepackage{multirow}
\begin{document}
\[
X(m,n) = \left\{\begin{array}{@{}lr@{}}
\multirow{2}{*}{x(n),} & \text{for }0\leq n\leq 1\\
& \text{or }0\leq n\leq 1\\
x(n-1), & \text{for }0\leq n\leq 1\\
x(n-1), & \text{for }0\leq n\leq 1
\end{array}\right\} = xy
\]
\end{document}
\multirow
collateral damage. I couldn't find information about it in LaTeX companion 2e, but \multirow{2}{*}{$x(n),$}
solves the problem.
For the question as it was originally posed, we can still use cases
very easily. We simply employ the technique of using \left.
at the start and then we can put \right\}
at the end:
\[
X(m, n) = \left.
\begin{cases}
x(n), & \text{for } 0 \leq n \leq 1 \\
x(n - 1), & \text{for } 0 \leq n \leq 1 \\
x(n - 1), & \text{for } 0 \leq n \leq 1
\end{cases}
\right\} = xy
\]
I'm not sure that you can span rows with cases
as in the edit, however.
cases
. Great job!
Feb 18, 2016 at 11:01
cases
environment, yes; but it does have a drawback, it inserts a spurious space (of width \nulldelimiterspace
, usually equal to 1.2pt) both between the “=” sign and the left brace, and between the last column and tht right brace. (Will @loved.by.Jesus read this reply posted more than two years after her/his comment?)
Essentially the same answer as Ignasi, but with the use of \text
for the word for
. (And with the \leqslant
symbol of amssymb
which I find much more elegant.)
\documentclass{article}
\usepackage{amsmath, amssymb}
\newcommand{\for}{\text{for }}
\begin{document}
\[
X(m,n)=
\left\{
\begin{array}{lr}
x(n),& \for 0\leqslant n \leqslant 1 \\
x(n-1),& \for 0\leqslant n \leqslant 1 \\
x(n-1),& \for 0\leqslant n \leqslant 1
\end{array}
\right\} = xy.
\]
\end{document}
Edit As for the modification recently asked:
\documentclass{article}
\usepackage{amsmath, amssymb}
\newcommand{\for}{\text{for }}
\begin{document}
\[
X(m,n)=
\left\{
\begin{array}{@{}lr@{}}
x(n),&
\begin{array}{r@{}}
\for 0\leqslant n \leqslant 1\\
\text{or } 0\leqslant x \leqslant 1
\end{array}\\
x(n-1),& \for 0\leqslant n \leqslant 1 \\
x(n-1),& \for 0\leqslant n \leqslant 1
\end{array}
\right\} = xy.
\]
\end{document}
(I didn't deem it necessary to define a new macro for the word or
since it is written only once. Note that it seems better this time to center the second column.)
Edit bis Added the @{}
specifications suggested by daleif
. No more centering.
This has already been addressed, but I can't remember where nor when. So here is a simple solution with the empheq
package, which loads mathtools
, hence amsmath
:
\documentclass{article}
\usepackage{amssymb}
\usepackage[overload]{empheq}
\newcommand{\for}{\text{for }}
\begin{document}
\begin{equation*}[right=\empheqrbrace{=xy.}]
X(m,n)=
\begin{cases}
x(n),& \for 0\leqslant n \leqslant 1 \\
x(n-1),& \for 0\leqslant n \leqslant 1 \\
x(n-1),& \for 0\leqslant n \leqslant 1
\end{cases}
\end{equation*}
\end{document}
[overload]
option and use \begin{empheq}[right=\empheqrbrace{=xy.}]{equation*} ......\end{empheq
instead.
[overload]
and dispose as you suggested, the code gives me error. Eliminating \begin{empheq}
and leaving only \begin{equation*}
is ok
equation*
, should be the mandatory argument of the empheq
environment, it's not a nested environment. See the exact code in my first comment.
Building upon the answer from Au101, what about nesting the cases
environments?:
\[
X(m, n) = \left.
\begin{cases}
x(n), &
\begin{cases}
\text{for } 0 \leq n \leq 1 \\
\text{or } 0 \leq n \leq 1
\end{cases} \\
x(n - 1), & \text{for } 0 \leq n \leq 1 \\
x(n - 1), & \text{for } 0 \leq n \leq 1
\end{cases}
\right\} = xy
\]
The nested braces are ugly, but this approach avoids the need for the multirow
or array
packages.
You may also want to try \begin{Bmatrix}\end{Bmatrix}
, for example
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{Bmatrix}
c & u & r & l & y
\\
b & r & a & c & e
\\
i & s &
\\
& c & o & o & l
\end{Bmatrix}
\end{equation}
\end{document}
For your specific example (thanks @Mico for the hint) you can tweak the definition of ams matrix to manipulate (overall) cell-aligment.
\documentclass{article}
\usepackage{amsmath}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% the following two definitions allow the usage of ams matrix environments
%% with an optional argument telling how to align the matrix, useful for
%% linear algebra texts, e.g.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\env@matrix{\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{*\c@MaxMatrixCols c}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\renewcommand*\env@matrix[1][c]{\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{*\c@MaxMatrixCols #1}}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{equation}
X(m,n)
=
\begin{Bmatrix}[l]
x(n),
&
\text{ for }
0\leq n\leq1
\\
x(n-1),
&
\text{ for }
0\leq n\leq1
\\
x(n-1),
&
\text{ for }
0\leq n\leq1
\end{Bmatrix}
=
xy
\end{equation}
\end{document}
The output is
Note that while matrix environments are easier and more straightforward to use than arrays, they are less powerful. For example, column-dependent alignment is not easily achievable.
I liked @Ken’s idea, but, once you have opted for a solution that uses nested “cases
-like” environments, there’s an obvious improvement that permits to get rid of the additional unwanted brace, and it is to use the facilities provided by the mathtools
package.
The mathtools
package offers a \newcases
command that lets you define, exactly, new “cases
-like” environments with custom settings; in particular, it lets you specify custom delimiters on either side. There exist already several answers on this site that describe this command (just search the site for \newcases
), so I’ll not dwell here on the details; however, the sample code below contains comments that should suffice as a quick, essential reference. The idea is to define two new “cases
-like” environments, one with braces on both sides, and one with empty delimiters on both sides; remember, however, that an empty delimiter actually contributes a horizontal space of width \nulldelimiterspace
, so you need to compensate for this by means of appropriate negative kerns.
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\usepackage{mathtools} % automatically loads "amsmath" too
\makeatletter
% Arguments for the "\newcases" command (from "mathtools.sty", amended):
% #1 <- name of the new environment;
% #2 <- separation between columns;
% #3 <- alignment preamble (see "The TeXbook", Ch. 22), left column;
% #4 <- alignment preamble, right column;
% #5 <- left delimiter (e.g., "\lbrace" for the standard "cases");
% #6 <- right delimiter (e.g., "." for the standard "cases");
% To illustrate the full range of possibilities, we'll now define *four*
% new "cases-like" environments (although we need only one of them):
% all of them have braces on both sides, but they differ in the context
% their contents are typeset in.
% Left column is math, right column is math:
\newcases{doublecases}
{\quad}
{$\m@th{##}$\hfil} {$\m@th{##}$\hfil}
{\lbrace} {\rbrace}
% Left column is math, right column is text:
\newcases{doublecases*}
{\quad}
{$\m@th{##}$\hfil} {{##}\hfil}
{\lbrace} {\rbrace}
% Left column is display-style math, right column is display-style math:
\newcases{ddoublecases}
{\quad}
{$\m@th\displaystyle{##}$\hfil} {$\m@th\displaystyle{##}$\hfil}
{\lbrace} {\rbrace}
% Left column is display-style math, right column is text:
\newcases{ddoublecases*}
{\quad}
{$\m@th\displaystyle{##}$\hfil} {{##}\hfil}
{\lbrace} {\rbrace}
% For the case (!) of the "case-like" environment with empty delimiters
% on both sides, however, we define only the variant we actually need:
% Left column is right-aligned text, right column... doesn't matter:
\newcases{nullcases}
{\quad}
{\hfil{##}} {{##}\hfil}
{.} {.}
\makeatother
\begin{document}
Some text before the equation.
\[
X(m, n) =
\begin{ddoublecases}
x(n), &
\kern -\nulldelimiterspace
\begin{nullcases} % beware of spaces!
for $0 \leq n \leq 1$\\
or $0 \leq n \leq 1$%
\end{nullcases}
\kern -\nulldelimiterspace
\\
x(n - 1), & \text{for $0 \leq n \leq 1$} \\
x(n - 1), & \text{for $0 \leq n \leq 1$}
\end{ddoublecases}
= xy
\]
Some text after the equation.
\end{document}
Here is the output:
\delta_{nm}=\begin{cases}
1, & \text{ if } m=n,\\
0, & \text{ ow.}
\end{cases}
If you want the exact output, including the closing braces for the cases, as well as the two conditions for the first case, you can use package delarray as follows:
\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{delarray}
\begin{document}
\begin{eqnarray*}
X(m, n)=
\begin{array}\{{ll}\}
x(n), & \text{ for } 0 \leq x \leq 1 \\
x(n-1), & \text{ for } 0 \leq x \leq 1 \\
x(n-1), & \text { for } 0 \leq x \leq 1 \\
\end{array}=xy
\end{eqnarray*}
\begin{eqnarray*}
X(m, n)=
\begin{array}\{{rl}\}
x(n), & {\begin{matrix}\text{ for }0 \leq x \leq 1 \\\text{ or }0 \leq x \leq 1 \end{matrix}} \\
x(n-1), & \text{ for } 0 \leq x \leq 1 \\
x(n-1), & \text { for } 0 \leq x \leq 1 \\
\end{array}=xy
\end{eqnarray*}
\end{document}
This package allows you to specify the position of each element in the array cell, as well as the delimiters for the entire array, in your case the curly braces spanning all three cases.
\[
…\]
preferable to$$
?