[Tex/LaTex] multiline eqnarray, but only one equation number

eqnarraynumbering

I want to build an array and refer to it as with equations. The array consists on two lines; however, I would like to refer it as only one.
My code is the following:

\documentclass[12pt,twoside,openright,a4paper]{book}
\usepackage{amsmath}
\begin{document}
As shown in Equation \ref{eq:2} ...

\begin{eqnarray}\label{eq:2}
    H_0: \ h(\mathbf{X}) = 0 \\
    H_1: \ h(\mathbf{X}) \neq 0
\end{eqnarray}
\end{document}

I get two equation numbers — one for each line. An alternative object type or any possible solution in order to get the formula in two lines but with only one equation number?

Best Answer

with use of the package amsmath:

enter image description here

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{equation}\label{eq:2}
\begin{aligned}
    H_0\colon &\quad h(\mathbf{X}) = 0 \\
    H_1\colon &\quad h(\mathbf{X}) \neq 0
\end{aligned}
\end{equation}
\end{document}

note:

  • eqnarray is deprecated for long time. rather use math environments provided by the package amsmath
  • in the case, that you like to have equation centered (and not aligned to aligned at for example :), than instead of aligned you should use gathered (as suggested Mico in his comment below):

\begin{equation}
\begin{gathered}\label{eq:2}
    H_0\colon\quad h(\mathbf{X}) = 0 \\
    H_1\colon\quad h(\mathbf{X}) \neq 0
\end{gathered}

(in your case since of equation has equal width the result is the same as before).

edit: the package amsmath define also options for placement of equation numbers at aligned ans gathered math environments (as pointed Bernard). for example at gathered we can write and obtain:

\begin{equation}
\begin{gathered}[t]\label{eq:2}
    H_0\colon\quad h(\mathbf{X}) = 0 \\
    H_1\colon\quad h(\mathbf{X}) \neq 0
\end{gathered}
\end{equation}

\begin{equation}
\begin{gathered}[b]\label{eq:2}
    H_0\colon\quad h(\mathbf{X}) = 0 \\
    H_1\colon\quad h(\mathbf{X}) \neq 0
\end{gathered}
\end{equation}

for more options and details for the package amsmath please read its documentation. it is part of any latex installation. also it is worth to read documentation for the package mathtools which is extension of amsmath.

enter image description here

Related Question