multiline eqnarray, but only one equation number

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?

• (1) as always on this site please post a full minimal example, not sniplets, that makes it a lot easier for others to test your code and provide solutions. (2) Never use eqnarray it is a broken construction (lucky for you not in this case), use amsmath and the envs in it. The manual for amsmath will tell you how to remove a single eqn number, or, perhaps better, how to add a single centered eq no to a two line alignment. May 25 '18 at 9:59

with use of the package amsmath:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\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{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{gathered}\label{eq:2}
\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{gathered}[t]\label{eq:2} H_0\colon\quad h(\mathbf{X}) = 0 \\ H_1\colon\quad h(\mathbf{X}) \neq 0 \end{gathered}$$

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


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.

• +1. You may also want to mention the gathered environment, in case the OP doesn't need to (or want to) perform any horizontal alignment across rows.
– Mico
May 25 '18 at 10:06
• @Mico, thank you very much. i edit answer accordingly :-) May 25 '18 at 10:18
• Fine, @Zarko! I'll remove my now useless comments May 25 '18 at 13:16

You have two alignment points to take care of (even if the result would be the same with gathered because of the actual data).

\documentclass[12pt,twoside,openright,a4paper]{book}
\usepackage{amsmath}

\begin{document}

As shown in Equation~\ref{eq:notfavorite}
\label{eq:notfavorite} \begin{alignedat}{2} &H_0\colon &\ h(\mathbf{X}) &= 0 \\ &H_1\colon &\ h(\mathbf{X}) &\neq 0 \end{alignedat}
and in Equation~\ref{eq:favorite}
\label{eq:favorite} \begin{alignedat}{2} &H_0\colon & h(\mathbf{X}) &= 0 \\ &H_1\colon & h(\mathbf{X}) &\neq 0 \end{alignedat}

\end{document}


Note the ~ between Equation and \ref. I'd prefer the second, with no added space.

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


Here we get the number on the upper line. No number at the bottom line