LaTeX forum ⇒ Math & Sciencealign 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

Postby x42bn6 » Mon Nov 30, 2009 8:36 pm

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?

Thanks in advance.

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
olofos
Posts: 56
Joined: Tue Nov 24, 2009 10:37 pm

align with annotations

Postby olofos » Tue Dec 01, 2009 1:04 pm

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*}
Hence the second & in your first line starts a new equation. To left-align your comments, just add an extra &:
\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

Postby holzensp » Thu Dec 03, 2009 3:15 pm

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}
\text{minimize}\quad&
	\sum_{ij}c_{ij}x_{ij}
	\label{obj}\\
\text{subject to}\quad&
	\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

Postby magicmoose » Fri Dec 04, 2009 1:19 am

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

Postby holzensp » Fri Dec 04, 2009 2:50 am

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
(46.39 KiB) Downloaded 697 times

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

Re: align with annotations

Postby magicmoose » Fri Dec 04, 2009 3:36 am

What is wrong with the references?

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

Re: align with annotations

Postby holzensp » Fri Dec 04, 2009 10:49 am

Well, \ref{everything} now results in "\forall i\quad(2)" instead of just "2"

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

Re: align with annotations

Postby holzensp » Fri Dec 04, 2009 11:28 am

I've put the alternatives in a more extensive example. The attachment contains the code in a listings environment.
Attachments
LP.pdf
(135.28 KiB) Downloaded 408 times

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

align with annotations

Postby magicmoose » Fri Dec 04, 2009 1:21 pm

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

Postby holzensp » Fri Dec 04, 2009 5:29 pm

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 :(


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 4 guests