Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a set of equations given by the following code:

\begin{equation}
\label{eqn:eraserStart}
    \max \, d
\end{equation}

\begin{equation}
    a_t \in \{0,1\} \, \forall t \in T
\end{equation}

\begin{equation}
    \sum_{\forall t \in T} a_t = 1
\end{equation}

\begin{equation}
    a_t \in [0,1] \, \forall t \in T
\end{equation}

\begin{equation}
    \sum_{\forall t \in T} c_t \leq m
\end{equation}

\begin{equation}
    d - U_d(t, C) \leq (1-a_t) \cdot Z \, \forall t \in T
\end{equation}

\begin{equation}
\label{eqn:eraserEnd}
    0 \leq k - U_a(t, C) \leq (1-a_t) \cdot Z \, \forall t \in T
\end{equation}

The output looks like this:

enter image description here

Whereas I wish it to look like this:

enter image description here

How can I achieve this?

share|improve this question
1  
\max is the preferred alternative to using \text{max} in maths environment. Plus its much neater! –  oLas May 4 '13 at 18:44
1  
My bad. Fixed that. Thanks. –  PhD May 4 '13 at 18:45

3 Answers 3

up vote 7 down vote accepted

Here's one possibility; I used an align environment to align the quantified expressions; to get the left parts centered, I used some boxes with centered content; the \Ceneq command places its argument in a box whose width correspomds to the wider expression:

\documentclass{report}
\usepackage{amsmath}

\newlength\longest
\newcommand\Ceneq[1]{%
  \makebox[\longest][c]{$#1$}}

\begin{document}

\settowidth\longest{$0 \leq k - U_a(t, C) \leq (1-a_t) \cdot Z$}
\begin{align}
\label{eqn:eraserStart}
\Ceneq{\max d} \\
\Ceneq{a_t \in \{0,1\}} &\qquad\forall t \in T \\
\Ceneq{\sum_{\forall t \in T} a_t = 1} \\
\Ceneq{a_t \in [0,1]} &\qquad\forall t \in T \\
\Ceneq{\sum_{\forall t \in T} c_t \leq m} \\
\Ceneq{d - U_d(t, C) \leq (1-a_t) \cdot Z} &\qquad\forall t \in T \label{eqn:eraserEnd} \\
\Ceneq{0 \leq k - U_a(t, C) \leq (1-a_t) \cdot Z} &\qquad\forall t \in T 
\end{align}

\end{document}

enter image description here

Using \displaystyle before \sum, you get the limits under the summation symbols:

\documentclass{report}
\usepackage{amsmath}

\newlength\longest
\newcommand\Ceneq[1]{%
  \makebox[\longest][c]{$#1$}}

\begin{document}

\settowidth\longest{$0 \leq k - U_a(t, C) \leq (1-a_t) \cdot Z$}
\begin{align}
\label{eqn:eraserStart}
\Ceneq{\max d} \\
\Ceneq{a_t \in \{0,1\}} &\qquad\forall t \in T \\
\Ceneq{\displaystyle\sum_{\forall t \in T} a_t = 1} \\
\Ceneq{a_t \in [0,1]} &\qquad\forall t \in T \\
\Ceneq{\displaystyle\sum_{\forall t \in T} c_t \leq m} \\
\Ceneq{d - U_d(t, C) \leq (1-a_t) \cdot Z} &\qquad\forall t \in T \label{eqn:eraserEnd} \\
\Ceneq{0 \leq k - U_a(t, C) \leq (1-a_t) \cdot Z} &\qquad\forall t \in T 
\end{align}

\end{document}

enter image description here

share|improve this answer

I did find an alternate way and this seems to work just fine. Probably a bit simpler than Gonzalo's solution. Caveat: You need to have either the IEEEtran document class or use the IEEEtrantools package

\begin{IEEEeqnarray}{Ccc} %3 column layout to align the equations
    \label{eqn:startEraser} \max d &&   \\ %empty 2nd/3rd columns
    \label{eqn:a_t=1}       a_t \in \{0,1\} & \quad & \forall t \in T   \\ %add \quad in 2nd column for spacing and \forall... in 3rd
    \label{eqn:sum a_t}     \sum_{\forall t \in T} a_t = 1 &&           \\
    \label{eqn:c_t=1}       c_t \in [0,1] & \quad & \forall t \in T     \\ %same here
    \label{eqn:sum c_t}     \sum_{\forall t \in T} c_t \leq m &&        \\
    \label{eqn:dZ}          d - U_d(t, C) \leq (1-a_t) \cdot Z & \quad & \forall t \in T   \\ %and here
    \label{eqn:eraserEnd}   0 \leq k - U_a(t, C) \leq (1-a_t) \cdot Z & \quad & \forall t \in T %and here   
\end{IEEEeqnarray}

Here's the output:

enter image description here

share|improve this answer

Here's my attempt at this. Looking at the problem, it seems you need three things:

  • Each row should have two columns.
  • The first column should be centered, and the second column should be aligned (say) a \quad to the right of it.
  • The lines should be numbered.

Multiple columns suggests align; centering of equations suggests gather. You can't have both at once, though you could do parallel aligned and gathered subenvironments as in this answer of mine...except that would give only one number for the whole display, violating the last requirement. A tabular would be perfect for the combination of the first two requirements, but that also doesn't number its lines. Still, there is no other environment that treats each line as a whole and also allows control over the alignment of each column, so tabular it is.

Well, tabu. I don't really use any special features but it's a complete improvement over the built-in tabular so I should advocate for it. I do the following:

  • There are, as promised, two columns of type c and l.
  • Between them there is a \quad by default.
  • Before the first column, we set up the line numbering by calling \refstepcounter on equation, the counter used by all the equation environments (including align and gather). Alas, this only sets the label locally, and thus it is forgotten once we reach the actual text where you might write \label, so I am forced to do some hackery with \@currentlabel to globalize it.
  • After that, we make a box the width of the entire line, stick a line number at the right end of it, and then declare the whole thing to have width zero so as not to disturb the rest of the table. That is, the line number is an overlay on the line. This is not how the amsmath environments do it, so it will cause problems if your lines are unusually long (or the page is unusually narrow).
  • Everything is between $$ so as to set it off as a display, like a real equation. Do not ever use this in real life! It's a literally primitive command and I only did it because I really want only the primitive behavior, not the stuff that makes equation work well.
  • For convenience, the whole thing is packaged as an environment I call align+ for lack of a better name.

I also wrote a simple macro \forallt to shorten the stuff in the second column. Now you can use it basically like you'd use any array environment.

\documentclass{article}
\usepackage{amsmath,tabu}
\makeatletter
\newenvironment{align+}
{$$\tabu
  {
    @{\refstepcounter{equation}%
      \global\let\@currentlabel\@currentlabel
      \rlap{\makebox[\linewidth]{\hfil$(\theequation)$}}
    }%
    >{\displaystyle}c%
    @{\quad}%
    >{\displaystyle}l%
  }
}
{\endtabu$$\ignorespacesafterend}
\makeatother
\newcommand*\forallt{\forall t \in T}
\begin{document}
\noindent
In the table below:
\begin{align+}
    \label{eq1}\max d \\
    a_t \in \{0,1\} & \forallt \\
    \sum_{\forall t \in T} a_t = 1 \\
    a_t \in [0,1] & \forallt \\
    \label{eq5}\sum_{\forall t \in T} c_t \leq m \\
    d - U_d(t, C) \leq (1-a_t) \cdot Z & \forallt \\
    0 \leq k - U_a(t, C) \leq (1-a_t) \cdot Z & \forallt
\end{align+}
on lines \ref{eq1} and \ref{eq5}\dots

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.