[Tex/LaTex] the actual function of “&” in math environment

math-modesyntax

First of all, I must and want to say that I really like the idea of this website. It's pretty awesome to have a place like this where you can ask all your questions regarding LaTeX/TeX. 😀

My question might be rather trivial.
In fact, I have not really figured out the actual function of the & sign in mathematical environments.
I know that one can use it in order to add explanations of variables next to mathematical formulas.
If I add e.g. the expression && i &= \text{interest} under a formula that contains the variable i, I can define that as the interest rate in the specific formula and in the final document it will appear next to the formula.

But what does the & exactly do? Why do I have to add two of it in order to have a correct typesetting.
As you might have already noticed, I haven't understood the syntax of it yet. 😀

It would be so nice if somebody could help me with this one.

Thank you very, very much in advance.

Best regards,

Marcel


OK, so I want to provide the code I promised yesterday.

The original code I referred to yesterday is this one:

\documentclass[a4paper,10pt]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\begin{document}

\begin{align*}
G(x) &= 0 & G &= \text{Gewinn} \\
&& x &= \text{Menge} \\
\Leftrightarrow E - K = 0 \\
&& E &= \text{Erlös} \\
&& K &= \text{Kosten} \\
\Leftrightarrow E = K \\
\Leftrightarrow p \cdot x = K_{f} + k_{v} \cdot x \\
&& p &= \text{Preis} \\
&& K_{f} &= \text{Fixkosten} \\
&& k_{v} &= \text{variable Kosten}\\
\Rightarrow x = \frac{K_{f}}{p - k_{v}}\\
\end{align*}

\end{document}

Code 1

I simply copy-pasted the structure from another forum and used it to express my own formulas, but did not really understand what it does – until yesterday. 🙂
With the explanations of & as an alignment marker I got yesterday, I managed to align the formulas at the arrow signs:

[\documentclass[a4paper,10pt]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\begin{document}

\begin{align*}
G(x) &= 0 & G &= \text{Gewinn} \\
&& x &= \text{Menge} \\
&\Leftrightarrow E - K = 0 \\
&& E &= \text{Erlös} \\
&& K &= \text{Kosten} \\
&\Leftrightarrow E = K \\
&\Leftrightarrow p \cdot x = K_{f} + k_{v} \cdot x \\
&& p &= \text{Preis} \\
&& K_{f} &= \text{Fixkosten} \\
&& k_{v} &= \text{variable Kosten}\\
&\Rightarrow x = \frac{K_{f}}{p - k_{v}}\\
&bzw.\ \boxed{p = \frac{K_{f}}{x} + k_{v}}
\end{align*}

\end{document}]

Code 2

That looks much tidier. So I think that I understood the basic functionality of &.
But what I'm still uncertain about is the meaning of &&.
I also experimented a bit with that and it appears to me that this is just meant to create space. Similar to using the tab button in programs like Word.
Did I get that right?

Thanks again. 😀

Best Answer

In TeX & is used for alignment. That is, aligning parts of equations on different lines. My favourite example is the cases environment and, as egreg says in the comments, other common examples include matrices, via array, tables, via tabular ,and the many amsmath alignment environments like align, split ...

If you want an ampersand in mathematics use \&:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\[ |x| = \begin{cases}
             x, &\text{if }x\ge0,\\
            -x, &\text{if }x<0.
         \end{cases}
\]

For an ampersand in math-mode type $\&$.

\end{document}

enter image description here