3

I have the following code:

\documentclass{article}
\usepackage{amsmath, amssymb, amsthm, graphicx, textcomp}
\begin{document}
d^2(A,B)=\begin{cases}
(a_1-b_1)^2(1+m^2) &&\text{if $AB$ has slope $m$} \\
(a_2-b_2)^2 &&\text{if $AB$ is a vertical line}
\end{cases}
\end{document}

but I get this output:

enter image description here

Is there a way to get the text on the right after the formulas, so that there are only two lines? Thanks.

4

You are using two alignment characters on each row; only one of those can be used on each line of a cases environment; if you want to increase the separation between the math expressions and the annotations, you can use \quad, or \qquad, or \hspace with an appropriate value:

\documentclass{article}
\usepackage{amsmath, amssymb, amsthm, graphicx, textcomp}

\begin{document}

\[
  d^2(A,B)=
  \begin{cases}
    (a_1-b_1)^2(1+m^2), &\text{if $AB$ has slope $m$}  \\
    (a_2-b_2)^2, &\text{if $AB$ is a vertical line}
  \end{cases}
\]

\[
  d^2(A,B)=
  \begin{cases}
    (a_1-b_1)^2(1+m^2), &\qquad\text{if $AB$ has slope $m$}  \\
    (a_2-b_2)^2, &\qquad\text{if $AB$ is a vertical line}
  \end{cases}
\]

\end{document}

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.