4

I am trying to generate this equation:

enter image description here

using the following:

\begin{equation}
    d(T,b)=\left\{\begin{matrix}
    0 & \mathrm{if branch has been covered,}\\ 
    v(d_{min}(t\in T, b)) & \mathrm{if the predicate has been executed at least twice,}\\ 
    1 & \mathrm{otherwise.}
    \end{matrix}\right.
\end{equation}

but I am getting this:

enter image description here

First of all, how can I fix the alignment to be exactly like the one in the above snippet? Also, how can I fix the text on the right? including the line break in the second value?

4 Answers 4

7

It is much simpler to do that with the dedicated cases environment, or its dcases* variant defined by mathtools):

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{equation}
d(T,b)=\begin{dcases*}
0 & if branch has been covered, \\
v(d_{\min}(t\in T, b)) & \parbox[t]{15em}{if the predicate has been executed at least twice,}\\
1 & otherwise. \\
\end{dcases*}
\end{equation}

\end{document} 

enter image description here

3

In order not to guess the width, you could use tabular:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\btext}[1]{%
  \begingroup\renewcommand{\arraystretch}{1}%
  \begin{tabular}[t]{@{}l@{}}#1\end{tabular}
  \endgroup
}

\begin{document}

\begin{equation}
d(T,b)=
\begin{cases}
  0                      & \text{if branch has been covered,}\\[0.5ex]
  v(d_{\min}(t\in T, b)) & \btext{if the predicate has been \\
                             executed at least twice,}\\[3ex]
  1 & \text{otherwise.}
\end{cases}
\end{equation}

\end{document}

The (local) resetting of \arraystretch is necessary because cases changes it. Some guessing is still needed, in order to separate the rows.

enter image description here

3

This is only a combination of array and matrix...but the enviroment cases it is the just and correct solution.

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools,amssymb}
 
\begin{document}
\begin{equation*}
   d(T,b)=\left\{\begin{array}{lll}
      0 \\ 
      v(d_{\min}(t\in T, b)) \\
      1
    \end{array}\right.
    \begin{matrix*}[l]
\text{if branch has been covered,}  & \\
\text{if the predicate has been executed at least twice,}& \\
\text{otherwise.}
\end{matrix*}
\end{equation*}

\end{document}

2

You can do this with the cases package.

\documentclass{article}
\usepackage{cases}

\begin{document}
\begin{numcases}{d(T,b)=}
  0                             & if branch has been covered, \nonumber \\
  v(d_{\mathrm{min}}(t\in T,b)) & \parbox[t]{11em}{if the predicate has been executed at least twice,} \nonumber \\
  1                             & otherwise \nonumber
\end{numcases}
\end{document}

The above code produces this result.

3
  • 1
    Is there an advantage, under some circumstances, of using the numcases environment of the cases package instead of the cases environment of the amsmath package?
    – Mico
    Jun 27, 2020 at 7:07
  • 1
    @Mico: If you want to number(and refer) the cases individually, it is a bit simpler than doing it via empheq. However, I'm not sure, it can be nested in another math environment (never tested).
    – Bernard
    Jun 27, 2020 at 9:00
  • @Mico I honestly don't know. Until I read the cases documentation I didn't know about the corresponding command in amsmath as I stumbled onto cases for reasons not related to mathematics. Jun 27, 2020 at 17:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .