## LaTeX forum ⇒ Math & Science ⇒ align with annotations

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
x42bn6
Posts: 14
Joined: Tue Apr 07, 2009 1:35 am

### align with annotations

Is the correct syntax to use align with some annotations as follows?

\begin{align*}
A\land B &= B\land A & \text{commutativity}\\
&= X & \text{as defined above}
\end{align*}

The reason I ask is because the annotations (commutativity, as defined above) don't right-align to the page, almost treating them as though there were part of another set of equations which I'm guessing what align is used for. However, I was told we could use align in this way for annotations.

Is this how syntactically this is done? If not, how is it done?

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

olofos
Posts: 56
Joined: Tue Nov 24, 2009 10:37 pm

### align with annotations

The align environment allows you to put several equations on each row, each aligned at an &-character. Each equation is also delimited by an &:
\begin{align*}
a &= 1 & b &= 2 \\
c &= 3 & d &= 4
\end{align*}
\begin{align*}
A\land B &= B\land A && \text{commutativity}\\
&= X && \text{as defined above}
\end{align*}

holzensp
Posts: 6
Joined: Thu Dec 03, 2009 2:57 pm

### align with annotations

I have this problem as well and, for me, the && is no solution. In typesetting Linear Programs (LPs), I want my domain constraints to be aligned to the far right (i.e. juxtaposed to the equation number). This makes the LP look right, but messes up the references:
\begin{align}
\sum_{ij}c_{ij}x_{ij}
\label{obj}\\
\sum_{j}x_{ij} \geq 1
\stepcounter{equation}
\label{everything}
\tag*{$\forall i\quad$(\theequation)}
\end{align}
References are wrong, though, as in \ref{everything}.


I've tried sticking the label inside that tag, but that puts the label out of scope, it seems. Is there a better way to do this?

Edit:
Also, I don't really want these domain constraints in a column of their own. Sometimes, the objective function (first line in the example above) can be quite wide and does not have a domain constraint, so it shouldn't be pushed to the left, because lower rows have domain constraints.

magicmoose
Posts: 90
Joined: Fri Nov 06, 2009 7:29 am

### Re: align with annotations

I don't understand what you want it to look like, could you maybe post an example showing what you want to do?

holzensp
Posts: 6
Joined: Thu Dec 03, 2009 2:57 pm

### Re: align with annotations

I want it to look exactly like what it looks like when I run the example code, but with correct references. If you run the code above, you get the attachment.
Attachments
LP.pdf

magicmoose
Posts: 90
Joined: Fri Nov 06, 2009 7:29 am

### Re: align with annotations

What is wrong with the references?

holzensp
Posts: 6
Joined: Thu Dec 03, 2009 2:57 pm

### Re: align with annotations

holzensp
Posts: 6
Joined: Thu Dec 03, 2009 2:57 pm

### Re: align with annotations

I've put the alternatives in a more extensive example. The attachment contains the code in a listings environment.
Attachments
LP.pdf

magicmoose
Posts: 90
Joined: Fri Nov 06, 2009 7:29 am

### align with annotations

Hi there,

This is the best I can do at the moment - it's not a very good solution, but I think it is what you are after. I am sure someone with more knowledge would be able to give a better answer.
I just stayed the same column as summation and added the appropriate amount of hspace to make it look right.
\begin{align}
\text{minimize}\quad & \sum_{i\in I}\sum_{j\in (P\cap \mathcal{A})} x_{ij}y_j-\sum_i\sum_j k_iy_j+N\cdot\sum_ik_i\\
\text{subject to}\quad & \sum_i x_{ij} = 1 \hspace{5cm}\forall j\in (P\cap \mathcal{A}) | j \geq \zeta
\label{alloneX}
\end{align}

Hope that helps

holzensp
Posts: 6
Joined: Thu Dec 03, 2009 2:57 pm

### Re: align with annotations

That requires manual tweaking of the horizontal spacing. Of course, for the example's sake, I just wrote down one constraint, but any real LP would have about a dozen. The domain constraints should be aligned to the right (i.e. all an equal distance to the equation numbers).

I'm thinking there must be a better way than the abuse of \tag* that I'm using and/or the manual spacing you suggest. I dove into the amsmath.sty for a bit, but I can't really see an entry point into the implementation of \tag* such that I get the reference right