3

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
  • (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.
    – daleif
    May 25 '18 at 9:59
8

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

3
  • 2
    +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 :-)
    – Zarko
    May 25 '18 at 10:18
  • Fine, @Zarko! I'll remove my now useless comments
    – Bernard
    May 25 '18 at 13:16
2

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}
\begin{equation}\label{eq:notfavorite}
\begin{alignedat}{2}
&H_0\colon &\  h(\mathbf{X}) &= 0 \\
&H_1\colon &\  h(\mathbf{X}) &\neq 0
\end{alignedat}
\end{equation}
and in Equation~\ref{eq:favorite}
\begin{equation}\label{eq:favorite}
\begin{alignedat}{2}
&H_0\colon &  h(\mathbf{X}) &= 0 \\
&H_1\colon &  h(\mathbf{X}) &\neq 0
\end{alignedat}
\end{equation}

\end{document}

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

enter image description here

0
        \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

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.