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.

I have defined a handy little macro to typeset matrix elements in braket-notation and now want to align the next line to a part of this matrix element, because the equations are really long and aligning to the equal sign would be a colossal waste of space. However, simply putting the & inside the arguments of my macro gives me:

! Misplaced alignment tab character &.
<argument> u_1u_2u_3L&
                  P
l.21  \end{split}

So, I was wondering, is there a way to define the macro in a better way that allows to do this, or is it simply not possible and I have to work with \hspace{-10ex} or something.

Minimal not working example:

\documentclass[a4paper,10pt]{report}
\usepackage{amsmath}

\newcommand{\matrixel}[3]{\left< #1\vphantom{#2#3}\right| #2\left| #3\vphantom{#1#2}\right>}

\begin{document}
 \begin{equation}
 \begin{split}
   \matrixel{u_1u_2u_3L}{&P}{u_1'u_2'u_3'L'} = (a +b)\\
   &\times (c+d)
 \end{split}
 \end{equation}
\end{document}          

Note: I'm a bit confused about the terminology. Is this really a "macro" I defined here? Feel free to edit if there's a better word.

share|improve this question
    
where do the &lt; and &gt; come from? (they're not in the macro as you wrote it.) have you fed something through a web site and which has translated "<" to "&lt;" ? or are you using an html editor which thinks it knows better than you? –  wasteofspace Jan 21 at 10:09
    
You can't have a & inside a \vphantom –  egreg Jan 21 at 10:11
    
@wasteofspace No, the &lt; is what kile gives me as output. So, I have no idea where they come from (or what they mean). –  fifaltra Jan 21 at 10:19
    
@fifaltra The output should be <argument>, as in my fix. I'm not using Kile, so I can't say. –  egreg Jan 21 at 11:40
    
@egreg Hm, then that's a kile bug, it also gives me LaTeX2e &lt;2009/09/24&gt; right at the beginning of the output. Anyway, thanks for the edit. –  fifaltra Jan 21 at 11:45

1 Answer 1

up vote 6 down vote accepted

You can't have a & inside a \vphantom, this will confuse the alignment process and produce many errors. Here's a workaround: for this particular case you use a macro \alignmentpoint (choose a different name, if you wish), which is made into a noop inside a special form of \vphantom:

\documentclass[a4paper,10pt]{report}
\usepackage{amsmath}

\newcommand{\matrixel}[3]{\left< #1\mvph{#2#3}\right| #2\left| #3\mvph{#1#2}\right>}
\newcommand{\alignmentpoint}{&}
\newcommand{\mvph}[1]{\vphantom{\def\alignmentpoint{}#1}}


\begin{document}
 \begin{equation}
 \begin{split}
   \matrixel{u_1u_2u_3L}{\alignmentpoint P}{u_1'u_2'u_3'L'} = (a +b)\\
   &\times (c+d)
 \end{split}
 \end{equation}
\end{document}

When \matrixel is not used in an alignment, the setting will make no harm.

enter image description here

share|improve this answer
    
so just for optimal educational value, to see if I understood this right: the \def redefines the \alignmentpoint to an empty string inside \vphantom? –  fifaltra Jan 21 at 10:31
    
@Mico, I agree, but aren't scaled < the same as scaled \langle? –  daleif Jan 21 at 10:31
    
@daleif surely so; but the real question is where the "&" came from, given that it doesn't appear in his mwe. telling him he shouldn't have an "&" when he didn't put one there is surely confusing. my guess is it's a kile issue. (i've never used kile ... having learned emacs in the 80s, i'm too old to change ;-) –  wasteofspace Jan 21 at 10:56
    
@wasteofspace, I think Mico deleted the comment I was refering to. –  daleif Jan 21 at 11:11
    
@wasteofspace yes it's a kile issue, and I think we should clean up the comments now, because our discussion will just confuse everyone now that it's edited out. –  fifaltra Jan 21 at 11:49

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.