3

I would like to show Vandermond polynomial.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$\begin{aligned}
    \Delta=(X_4-X_3)&(X_4-X_2)&(X_4-X_1)\\
                    &(X_3-X_2)&(X_3-X_1)\\
                    &         &(X_2-X1)
\end{aligned}$$
\end{document}

However, it inserts unwanted white space.

my output

How can I resolve this?

Monday
  • 33
  • 1
    (1) where exactly are yor alignments here? Remember the numbner of &'s per row is 2 x <number of alignments> - 1, so if you have two alignments you need 3 &s on each line. (2) Aligned adds space between alignments, if you do not want that use alignedat and remember it takes a mandatory argument. – daleif Oct 11 '23 at 11:04
  • You are not supposed to use $$ in the regular LaTeX, even though markdown editors which implement MathJax promote $$. You should use \[...\], instead. See this question for more info. – Celdor Oct 11 '23 at 11:21

2 Answers2

3

aligned as well as any other align-like environment creates columns similarly to tabular environment. Each column is separated by & and each row ends with \\. Alignment in columns alternates between right and left starting from the right. Additionally, align and aligned create small space between every second column or group of pairs.

In your case the last column falls into the very next group, hence the extra space and it is right aligned w.r.t. the other part, so you could expect some tiny extra space as well.

You could use align environment without any groups or & and right-align the whole thing

\begin{align*}
    \Delta = (X_4-X_3)(X_4-X_2)(X_4-X_1) \\
                      (X_3-X_2)(X_3-X_1) \\
                               (X_2-X_1)
\end{align*}

You could also use alignat* or its counterpart alignedat to eliminate extra spacing between groups. Then, double && would keep each cell right aligned. Note, alignat takes a mandatory argument n to specify a number of groups of paired columns. Usually the formulae is n/2 rounded to the next integer, where n denotes a number of columns. Also note the extra {} after =. This is to let LaTeX add the standard space around an operator

\begin{alignat*}{4}
    \Delta &={} &(X_4-X_3)&&(X_4-X_2)&&(X_4-X_1) \\
           &    &         &&(X_3-X_2)&&(X_3-X_1) \\
           &    &         &&         &&(X_2-X_1)
\end{alignat*}

EDIT. I should have pointed out an issue related to vertical spacing when using align-like environments. Please see this answer for the details.

Here's the fill code with both examples

\documentclass{article}
\usepackage{amsmath}

\begin{document} \begin{align} \Delta = (X_4-X_3)(X_4-X_2)(X_4-X_1) \ (X_3-X_2)(X_3-X_1) \ (X_2-X_1) \end{align}

\begin{alignat}{4} \Delta &={} &(X_4-X_3)&&(X_4-X_2)&&(X_4-X_1) \ & & &&(X_3-X_2)&&(X_3-X_1) \ & & && &&(X_2-X_1) \end{alignat} \end{document}

enter image description here

Celdor
  • 9,058
  • Please have a look at the picture in my answer, which shows that align* is not generally the best choice. – egreg Oct 11 '23 at 20:09
  • @egreg It's an issue I sometimes forget to mention about. I added a note and link to you answer, so that OP can see the difference. Thanks. – Celdor Oct 12 '23 at 09:34
2

With aligned you're allowed to have several pairs of right- and left-aligned columns, with space between the pairs.

You can exploit the fact that the parenthesized expressions all have the same width and that the first column in aligned is right aligned, so alignment will be automatic

\[
\begin{aligned}
  \Delta=(X_4-X_3)(X_4-X_2)(X_4-X_1)\\
                  (X_3-X_2)(X_3-X_1)\\
                           (X_2-X_1)
\end{aligned}
\]

but please remember that $$ is never to be used in a LaTeX document environment. If you know what you're doing, there are selected situations where an environment may be defined using $$, but this requires having read the TeXbook at least ten times.

Full example, where I added a comparison with align* to show that you should use aligned whenever possible.

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

You can exploit the fact that the parenthesized expressions all have the same width and that the first column in \texttt{aligned} is right aligned, so alignment will be automatic [ \begin{aligned} \Delta=(X_4-X_3)(X_4-X_2)(X_4-X_1)\ (X_3-X_2)(X_3-X_1)\ (X_2-X_1) \end{aligned} ] but please remember that \verb|$$| is never to be used in a \LaTeX\ \texttt{document} environment. If you know what you're doing, there are selected situations where an environment may be defined using \verb|$$|, but this requires having read the \TeX book at least ten times.

You can exploit the fact that the parenthesized expressions all have the same width and that the first column in \texttt{align} is right aligned, so alignment will be automatic \begin{align} \Delta=(X_4-X_3)(X_4-X_2)(X_4-X_1)\ (X_3-X_2)(X_3-X_1)\ (X_2-X_1) \end{align*} but you can notice a difference with the previous display in that the vertical spacing is bigger here.

\end{document}

enter image description here

Use alignedat for multiple alignment points in case you cannot count on the natural width of the objects. This also creates pairs of right- and left-aligned columns, but adds no space between them.

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

You can also use \texttt{alignedat}, but it's really overkill [ \begin{alignedat}{3} \Delta=(X_4-X_3)&&(X_4-X_2)&&(X_4-X_1)\ &&(X_3-X_2)&&(X_3-X_1)\ && &&(X_2-X_1) \end{alignedat} ]

\end{document}

enter image description here

egreg
  • 1,121,712