# How can I write cases with grouping braces on both left and right side, and split the condition into two lines in LaTeX?

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

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


• How comes that x(n) is not typeset in math mode? Apr 27, 2015 at 14:56
• @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. Apr 27, 2015 at 15:04
• how does one do it with a single curly bracket in front? Nov 10, 2018 at 17:24
• @CharlieParker replace \right\} with \right. Nov 10, 2018 at 17:45
• @CharlieParker The command is \right. . You missed the dot . . Apr 10, 2021 at 18:10

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.

• that's my favourite answer, because of simplicity and keeping the original formulation with cases. Great job! Feb 18, 2016 at 11:01
• 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, 2018 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. Apr 8, 2018 at 18:06
• @loved.by.Jesus: They are explained in several manuals, for example in The TeXbook.
– GuM
Apr 10, 2018 at 17:59
• how does one do it with a single curly bracket in front? Nov 10, 2018 at 17:24

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


• I had errors with the package, then, in case of an error with the package: \usepackage[overload]{empheq}, consult this link Oct 12, 2018 at 7:16
• @Antonio: Remove the [overload] option and use \begin{empheq}[right=\empheqrbrace{=xy.}]{equation*} ......\end{empheq instead. Oct 12, 2018 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 Oct 16, 2018 at 9:36
• For me both have no problem. Do you have errors with this single code? And which errors? Oct 16, 2018 at 9:47
• 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. Oct 16, 2018 at 10:39

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.

• array doesn't come from a separate package. It's amsmath, right? Aug 7, 2020 at 1:21

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}
{$\m@th{##}$\hfil} {$\m@th{##}$\hfil}
{\lbrace} {\rbrace}

% Left column is math, right column is text:
\newcases{doublecases*}
{$\m@th{##}$\hfil} {{##}\hfil}
{\lbrace} {\rbrace}

% Left column is display-style math, right column is display-style math:
\newcases{ddoublecases}
{$\m@th\displaystyle{##}$\hfil} {$\m@th\displaystyle{##}$\hfil}
{\lbrace} {\rbrace}

% Left column is display-style math, right column is text:
\newcases{ddoublecases*}
{$\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}
{\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:

You may also want to try \begin{Bmatrix}\end{Bmatrix}, for example

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$\begin{Bmatrix} c & u & r & l & y \\ b & r & a & c & e \\ i & s & \\ & c & o & o & l \end{Bmatrix}$$
\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}
$$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{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.

– Mico
Apr 26, 2016 at 9:07
• @Mico I've fixed my example, but the downvote still there :-( Apr 29, 2016 at 5:40
• 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, 2016 at 6:06
\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.

• There's no need for eqnarray. Instead, just use $...$.
– Werner
Feb 17, 2021 at 19:10