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.

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?

share|improve this question

migrated from stackoverflow.com Sep 10 '11 at 13:38

This question came from our site for professional and enthusiast programmers.

    
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? –  Loop Space Sep 13 '11 at 18:55
    
Of course, that would be brilliant, but I would be satisfied without this extra feature. –  JF Meier Sep 13 '11 at 19:00

3 Answers 3

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}
share|improve this answer
1  
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}. –  JF Meier Sep 10 '11 at 19:35

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

share|improve this answer
    
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 '11 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. –  eudoxos Sep 10 '11 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 '11 at 10:33
up vote 2 down vote accepted

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.

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.