# Remember position of equal sign from one align environment to the next

As you know, the align-environment puts all positions marked with & (normally the equals sign) exactly beneath each other. I now want to save the position LaTeX calculates for & and use it again later. In more detail, I have something like that:

\begin{xyz}
\begin{align}
x &= a \\
&= b   %store the position of & in \positionequal
\end{align}
\end{xyz}
\begin{xyz}
\begin{align} %read \positionequal and use it to put & at the right position
&= c
\end{align}
\end{xyz}


The things marked with % are unclear to me:

How to I find out this position, save it (so that it does not get lost from one xyz-environment to the next) and the use it again?

• If stuff in the second align is wider than in the first, do you want it to feedback and make the first one adjust its alignment? Sep 13, 2011 at 18:55
• Of course, that would be brilliant, but I would be satisfied without this extra feature. Sep 13, 2011 at 19:00

use \phantom{...} with the widest element from the earlier environment, i.e., the one that causes align to calculate the position. in your example,

\begin{xyz}
\begin{align}
x &= a \\
&= b   %store the position of & in \positionequal
\end{align}
\end{xyz}
\begin{xyz}
\begin{align} %read \positionequal and use it to put & at the right position
\phantom{x} &= c
\end{align}
\end{xyz}

• This is a good idea and should do the job. Nevertheless, I was hoping for something more "automatic", since (for some complicated reason) I am faced with a situation like above a lot of times, and the solution above makes me "guess" the longest element of every {align}. Sep 10, 2011 at 19:35

Although it is not the nicest thing to do, it seems possible to solve my problem by using \pdfsavepos or the zref package.

It gives you access to the distance between the beginning and end of the Lefthand side of your equation, so that you can reproduce this distance by an appropriate \hspace later.

Use \intertext for the text between evironments, that way you will have all the & marks aligned in the same position. See e.g. here; they say it is only for short text, but IIRC I was able to stuff long stretches of text and sectioning commands in there without issues (YMMV).

• This is not what I intended to do. As you see, my two align-environments are in different environments (which I just called xyz), so I cannot use the \intertext-command.
– JF Meier
Sep 10, 2011 at 8:46
• @JF Meier: sorry, I overlooked that. If you are the author of xyz environment, you could avoid the nesting problem by split its beginning and end into stand-along commands like \startxyz\begin{align}...&=...\intertext{\stopxyz ... \startxyz} ... &= ...\end{align}\stopxyz, or use \beginxyz...\endxyz. Sep 10, 2011 at 8:52
• Although I am the author of the xyz-environment, it uses a "true" environment (namely preview from the preview-package) which cannot be avoided. Imagine that xyz is something like a minipage.
– JF Meier
Sep 10, 2011 at 10:33