9

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?

David Carlisle
  • 757,742

3 Answers3

4

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}
David Carlisle
  • 757,742
  • 3
    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}. – J Fabian Meier Sep 10 '11 at 19:35
2

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).

David Carlisle
  • 757,742
eudoxos
  • 2,973
  • 1
    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. –  Sep 10 '11 at 08: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. – eudoxos Sep 10 '11 at 08: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. –  Sep 10 '11 at 10:33
2

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.

N.N.
  • 36,163