# An array in an equation with curly braces in both sides

I am trying to generate the following equation:

I am working with an old file (I have not written it) that already has the following code for this equation:

\delta(x)\equiv\left\{\all\begin{aligned} 0,\quad \text{if}\;x\ne 0\\ \infty,\quad \text{if}\; x=0 \end{aligned}\right\}\quad \text{with}\quad\int_{-\infty}^{+\infty}\delta(x)\;dx=1.


But this code doesn't work. Do you know what is wrong with that?

• After removing the \all in the second line, your code seems to produce the desired result – siracusa Apr 26 at 0:38

You can compare four ways to get the result.

The alignment with the original code happens essentially by chance and needs visual formatting (additions of \quad and \;).

With Bmatrix the alignment is again by chance (the second column items have the same width).

With cases, adding \left. and \right., a bigger space after \equiv is used.

The best, in my opinion, is to use \left\{ and \right\}, with a nested aligned so you can clearly state the desired left alignment of both columns.

In any case, it should be \text{if $x=0$}, so no awkward explicit \; is needed (which is not a normal interword space). Also \, should precede dx, not \;.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\subsubsection*{Original without \texttt{\string\all}}
\delta(x)\equiv\left\{\begin{aligned} 0,\quad \text{if}\;x\ne 0\\ \infty,\quad \text{if}\; x=0 \end{aligned}\right\}\quad \text{with}\quad\int_{-\infty}^{+\infty}\delta(x)\;dx=1.

\subsubsection*{With \texttt{Bmatrix}}
$$\delta(x)\equiv \begin{Bmatrix} 0, & \text{if x\ne 0} \\ \infty, & \text{if x=0} \end{Bmatrix} \quad\text{with}\quad \int_{-\infty}^{+\infty}\delta(x)\,dx=1.$$

\subsubsection*{With \texttt{cases}}
$$\delta(x)\equiv \left. \begin{cases} 0, & \text{if x\ne 0} \\ \infty, & \text{if x=0} \end{cases}\right\} \quad\text{with}\quad \int_{-\infty}^{+\infty}\delta(x)\,dx=1.$$

\subsubsection*{With \texttt{aligned}}
\delta(x)\equiv \left\{ \begin{aligned} &0, && \text{if x\ne 0} \\ &\infty, && \text{if x=0} \end{aligned} \right\} \quad\text{with}\quad \int_{-\infty}^{+\infty}\delta(x)\,dx=1.

\end{document}


As @siracusa has already pointed out in a comment, the \all directive should be removed. The only other significant change I recommend making to your code is adding & alignment points inside the aligned environment. (After all, why employ an algin environment if no alignment is performed?)

\documentclass{article}
\usepackage{amsmath} % for 'aligned' environment
\begin{document}

\delta(x)\equiv \left\{ \begin{aligned} 0, \quad&\text{if x\ne 0}\\ \infty,\quad&\text{if x=0} \end{aligned} \right\}\,, \qquad\text{with } \int_{-\infty}^{+\infty}\! \delta(x)\,dx=1.
\end{document}


You can use cases to simplify it a little bit and, of course, remove \all as @siracusa said.

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

$$\delta(x)\equiv\left.\begin{cases} 0, & \text{if } x \ne 0 \\ \infty, & \text{if } x = 0 \end{cases}\right\}, \quad\text{with } \int_{-\infty}^{+\infty}\delta(x)\; dx = 1.$$

\end{document}


• Can you explain \left. please? I am guessing it is somehow affecting the size of the opening curly bracket? – Anush Apr 26 at 6:17
• The \left and \right in LaTeX must appear in pairs, each opening \left must have its closing \right the same as parentheses () in programming. In your case you only need the \right\} because cases inserts its own \left\{, so you must add a "virtual" \left. just to balance the closing \right\}. – AboAmmar Apr 26 at 10:40

The simplest way is probably the Bmatrix environment.

Unrelated: I took the opportunity to improve the spacing in the integral.

\documentclass{article}
\usepackage{mathtools}

\begin{document}

$$\delta(x)\equiv \begin{Bmatrix} 0, & \text{if } x \ne 0 \\ \infty, & \text{if } x = 0 \end{Bmatrix}, \quad\text{with }\int_{-\infty}^{\mathrlap{+\infty}}\delta(x)\,dx = 1.$$

\end{document}


Using only array as another alternative with a basic syntax. I have also used double \!\! negative space, before and after to have the two bracket more closer. See the figure and the MWE.

\documentclass{article}
\usepackage{amsmath} % for '\text' macro
\begin{document}
$\delta(x)\equiv \Biggl\{ \begin{array}{@{}cl@{}} 0, & \text{ if x \ne 0} \\ \infty, & \text{ if x = 0} \end{array} \Biggr\}, \quad\text{with}\quad \int_{-\infty}^{+\infty}\delta(x)dx=1.$
\end{document}

• @Mico Thank you very much for your preciuous suggestion. My always best regards. You are free to edit my answer if you prefer. :-) I have understood all :-) – Sebastiano Apr 28 at 21:31