5

I had some problems while trying to align some equations in an align* environment. The output should be something like this:

As you can see, all the + symbols are vertically aligned, and so are the letters after them. I tried with an align* environment to get a similar result, but I was not able to align the symbols nor the letters. Here is my code and output:

\begin{align*}
a &+2\alpha az &+3\alpha^2 az^2 &+4\alpha^3az^3 &+5\alpha^4az^4 +\mbox{ecc.}\\
&+bz &+2\alpha bz^2 &+3\alpha^2 bz^3 &+4\alpha^4bz^4,
\end{align*}

Is there a manner to get a more elegant result, without all those white spaces inside the sums? Thank you!

4 Answers 4

3

I don't think you want centering, but rather that the powers of z are aligned to each other.

In order to avoid to type &+{}& for each addition symbol, I define a handy shortcut.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

With all variables spelled out
\begin{equation*}
\begingroup\lccode`~=`+ \lowercase{\endgroup\edef~}{&\mathchar\the\mathcode`+{}&}
\mathcode`+=\string"8000
\begin{alignedat}{6}
a + 2\alpha az + 3\alpha^2 az^2 + 4\alpha^3 az^3 + 5\alpha^4 az^4 + \text{ecc.}\\
  +         bz + 2\alpha   bz^2 + 3\alpha^2 bz^3 + 4\alpha^4 bz^4 &,
\end{alignedat}
\end{equation*}
and like the original
\begin{equation*}
\begingroup\lccode`~=`+ \lowercase{\endgroup\edef~}{&\mathchar\the\mathcode`+{}&}
\mathcode`+=\string"8000
\begingroup\lccode`~=`* \lowercase{\endgroup\def~}#1{\hphantom{#1}}
\mathcode`*=\string"8000
\begin{alignedat}{6}
a + 2\alpha az + 3\alpha^2 az^2 + 4\alpha^3 az^3 + 5\alpha^4 az^4 + \text{etc.,}\\
  +         b*{z} + 2\alpha   b*{z^2} + 3\alpha^2 b*{z^3} + 4\alpha^4 b*{z^4}
\end{alignedat}
\end{equation*}

\end{document}

enter image description here

2
  • Thank you Enrico, that's exactly what I needed! Is there a way to add more than two rows, with three different spacing from the beginning?
    – Fabio Ori
    Dec 30, 2018 at 11:30
  • @FabioOri Can't guess, sorry.
    – egreg
    Dec 30, 2018 at 11:49
7

align gives alternating left and right alignment, but here I think you want centering so

enter image description here

\documentclass{article}

\usepackage{array,amsmath}

\begin{document}

\[
  \begin{array}{*{20}{@{}>{{}}c<{{}}@{}}}
a &+&2\alpha az &+&3\alpha^2 az^2 &+&4\alpha^3az^3 &+&5\alpha^4az^4 &+&\mbox{ecc.}\\
&+&bz &+&2\alpha bz^2 &+&3\alpha^2 bz^3 &+&4\alpha^4bz^4,
  \end{array}
\]
\end{document}
0
5

Here is a way with the alignat* environment and the eqparbox package:

\documentclass{article}

\usepackage{mathtools, eqparbox}
\newcommand{\eqmathbox}[2][T]{\eqmakebox[#1]{$\displaystyle#2$}}

\begin{document}

\begin{alignat*}{4}
a &+\eqmathbox{2\alpha az} & & +\eqmathbox[T2]{3\alpha^2 az^2}& & + \eqmathbox[T3]{4\alpha^3az^3} & & +\eqmathbox[T4]{5\alpha^4az^4} +\mbox{\&c.}\\
&+\eqmathbox{bz} & & +\eqmathbox[T2]{2\alpha bz^2} & & +\eqmathbox[T3]{3\alpha^2 bz^3} & & +\eqmathbox[T4]{4\alpha^4bz^4},
\end{alignat*}

\end{document} 

enter image description here

3

The same array thing but simpler and right aligned. I use \setlength{\arraycolsep}{0pt} to keep the natural spacing of the binary operator +.

\documentclass[a4paper]{article}
\usepackage{amsmath,array}

\begin{document}

\[\setlength{\arraycolsep}{0pt}
\begin{array}{*6{>{{}}r<{{}}}}
a +& 2\alpha az +& 3\alpha^2 az^2 +& 4\alpha^3az^3  +& 5\alpha^4az^4 +& \mbox{ecc.},\\
  +& bz         +& 2\alpha bz^2   +& 3\alpha^2 bz^3 +& 4\alpha^4bz^4 \phantom{{}+{}}&
\end{array}
\]

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .