7

I want to write this equation in latex:

enter image description here

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?

15

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} 

enter image description here

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

11

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}

enter image description here

  • This info is also very helpful – user38375 Mar 28 '15 at 9:53

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.