116

The code i used to write

this

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

enter image description here

I appreciate any help.

Edited: I'm sorry to add this but what if I want to write this enter image description here

89
\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}

enter image description here

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}

enter image description here

  • 7
    How comes that x(n) is not typeset in math mode? – Franck Pastor Apr 27 '15 at 14:56
  • 4
    @fpast Probably it's a \multirow collateral damage. I couldn't find information about it in LaTeX companion 2e, but \multirow{2}{*}{$x(n),$} solves the problem. – Ignasi Apr 27 '15 at 15:04
  • 1
    how does one do it with a single curly bracket in front? – Charlie Parker Nov 10 '18 at 17:24
  • 3
    @CharlieParker replace \right\} with \right. – Ignasi Nov 10 '18 at 17:45
90

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
\]

enter image description here

I'm not sure that you can span rows with cases as in the edit, however.

  • 3
    that's my favourite answer, because of simplicity and keeping the original formulation with cases. Great job! – loved.by.Jesus Feb 18 '16 at 11:01
  • 1
    Apparently simple, sure, and it keeps the original 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?) – GuM Apr 6 '18 at 22:18
  • @GuM I read it, of course, stack-overflow notifies about replies ;). Thanks for mentioning, what I think it is the only drawback of this answer. Now the info is complete! — I wonder how you know these intricacies about LaTeX; hat off. – loved.by.Jesus Apr 8 '18 at 18:06
  • @loved.by.Jesus: They are explained in several manuals, for example in The TeXbook. – GuM Apr 10 '18 at 17:59
  • how does one do it with a single curly bracket in front? – Charlie Parker Nov 10 '18 at 17:24
17

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}

enter image description here

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.

enter image description here

14

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} 

enter image description here

  • I had errors with the package, then, in case of an error with the package: \usepackage[overload]{empheq}, consult this link – Antonio Oct 12 '18 at 7:16
  • @Antonio: Remove the [overload] option and use \begin{empheq}[right=\empheqrbrace{=xy.}]{equation*} ......\end{empheq instead. – Bernard Oct 12 '18 at 11:30
  • I followed your variations, but if I remove [overload] and dispose as you suggested, the code gives me error. Eliminating \begin{empheq} and leaving only \begin{equation*} is ok – Antonio Oct 16 '18 at 9:36
  • 1
    For me both have no problem. Do you have errors with this single code? And which errors? – Bernard Oct 16 '18 at 9:47
  • 1
    The name of the environment, equation*, should be the mandatory argument of the empheq environment, it's not a nested environment. See the exact code in my first comment. – Bernard Oct 16 '18 at 10:39
7

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

I'm ignoring the fact that the math is nonsensical.

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.

  • 2
    Please clarify how your suggestion addresses the OP's typesetting needs. E.g., please post a full example. – Mico Apr 26 '16 at 9:07
  • 1
    @Mico I've fixed my example, but the downvote still there :-( – Oskar Limka Apr 29 '16 at 5:40
  • 1
    Well, it wasn't me who downvoted, but I've upvoted the answer to remove the -1. I still think you should make the example code more relevant and applicable to the OP's question. – Mico Apr 29 '16 at 6:06
7

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
\]

LaTeX output

The nested braces are ugly, but this approach avoids the need for the multirow or array packages.

6

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:

Output of the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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