Write this equation in latex

I want to write this equation in latex:

I need that comments be in right side.

I did something like this but it has some flaws.

   \begin{eqnarray}
\label{cons1}
% \begin{aligned}
x_i+w_{mi}\le X_j   \hfill \hfill\text{if i is to the left of j}\\
\label{cons2}
x_i-w_{mj}\ge X_j   \hfill \hfill\text{if i is to the right of j}\\
\label{cons3}
y_i+h_{mi}\le y_j   \hfill \hfill\text{if i is below of j}\\
\label{cons4}
y_i-h_{mj}\ge y_j    \hfill \hfill\text{if i is above of j}
%\end{aligned}
\end{eqnarray}


Where did I make mistake?

You would probably want to use an align environment

\documentclass{article}

\usepackage{amsmath}

\begin{document}
\begin{align}
\label{cons1}
x_i+w_{mi}&\le X_j   &&\text{if $i$ is to the left of $j$}\\
\label{cons2}
x_i-w_{mj}&\ge X_j   &&\text{if $i$ is to the right of $j$}\\
\label{cons3}
y_i+h_{mi}&\le y_j   &&\text{if $i$ is below of $j$}\\
\label{cons4}
y_i-h_{mj}&\ge y_j   &&\text{if $i$ is above of $j$}
\end{align}
\end{document}


You shouldn't use eqnarray in LaTeX, see eqnarray vs align

You can use alignat

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat}{2}
\label{cons1}
&x_i+w_{mi}\le X_j   & \qquad & \text{if $i$ is to the left of $j$}\\
\label{cons2}
&x_i-w_{mj}\ge X_j   &        & \text{if $i$ is to the right of $j$}\\
\label{cons3}
&y_i+h_{mi}\le y_j   &        & \text{if $i$ is below of $j$}\\
\label{cons4}
&y_i-h_{mj}\ge y_j    &       & \text{if $i$ is above of $j$}
\end{alignat}
\end{document}


• This info is also very helpful Mar 28, 2015 at 9:53