# Align two inequalities

I am trying to align two inequlities vertically. The \le signs should have the same horizontal positions and the term in the should be centered. My first attempt:

\begin{align*}
\sum a &\le \sum b &\le \sum c \\
\log \sum a &\le \log \sum b &\le \log \sum c
\end{align*}


Doesn't work. My second attempt:

$\begin{array}{rcccl} \sum a &\le& \sum b &\le& \sum c \\ \log \sum a &\le& \log \sum b &\le& \log \sum c \end{array}$


The alignment is good, but the sum signs are smaller than in the align environment.

What is the "best" way to do this LaTeX?

-

## 6 Answers

alignat is your friend:

\begin{alignat*}{2}
\sum a &\le &\sum b &\le \sum c \\
\log \sum a &\le{} &\log \sum b &\le \log \sum c
\end{alignat*}


produces:

I needed to add two extra alignment characters between the columns, and a {} to make the \le a binary operator. The number of &'s should be 2n-1 where n is the argument given (2 in the case above).

Although now that I read the question again I realize I didn't answer it. It seems that you want the \sum term to be centered...

The only way I can think of doing it is a bit ugly:

\newlength{\yuckkyhack}
\settowidth{\yuckkyhack}{$\displaystyle\log \sum b$}
\begin{alignat*}{2}
\sum a &{}\le{} &\makebox[\yuckkyhack]{$\displaystyle\sum b$} {}&\le \sum c \\
\log \sum a &\le{} &\log \sum b &\le \log \sum c
\end{alignat*}


which gives the desired result (I think):

but requires manual selection of the largest bit of text, and use of a length...any ideas for improvement?

-
The spacing before the second log in the second line is wrong. Writing &\le {} &\log might fix this. –  Philipp Oct 18 '10 at 19:39
Thanks! for the second time today... –  Yossi Farjoun Oct 18 '10 at 20:39
Your yuckkyhack is exactly what I did. =) –  TH. Oct 18 '10 at 21:39
In this case they are very similar, I agree, but I think that the use of alignat is more appropriate for problems of this nature. It would be nice if there was an environment similar to alignat where the alignment character and the "next column" character where different (though I can't think which character to use for that), then omitting the alignment character could signal that the cell should be centered. I wouldn't know where to start even. –  Yossi Farjoun Oct 18 '10 at 22:20
This works quite well, although I hoped that there is an easier way. –  aurevoirlesenfants Oct 19 '10 at 14:41

Is this horse dead yet....Since my other answer got accepted, I don't want to change it. So, instead, I'm adding my thoughts here in a new answer.

How about this:

\begin{equation*}
\begin{aligned}\sum a\le{}&\\\log \sum a\le{}& \end{aligned}\!
\begin{gathered}\sum b\\\log\sum b\end{gathered}\!
\begin{aligned}{}\le& \sum c \\{}\le& \log \sum c \end{aligned}
\end{equation*}


which produces:

No hackery involved, but the writing isn't as "linear" since you need to split the equations into columns yourself. Note also the negative space that is required to get better spacing between the columns.

Here is one more solution:

\usepackage{array}
\begin{document}

\newcolumntype{C}{>{$$\displaystyle}c<{$$}@{}}
\newcolumntype{L}{>{$$\displaystyle}l<{$$}@{}}
\newcolumntype{R}{>{$$\displaystyle}r<{$$}@{}}

\center{
\begin{tabular}{RCL}
\sum a \le{} & \sum b &\le \sum c \\
\log \sum a\le{} &\log \sum b &{}\le \log \sum c
\end{tabular}

\end{document}


Oh, one caveat: I have no idea how to have more than one equation number with this solution.

-
Maybe this is the better solution, but splitting the equation into columns is not so natural. So I think both solutions should be mentioned. Anyway, thanks for your effort. –  aurevoirlesenfants Oct 20 '10 at 12:34

As documented in amsmath's doc if you want to have all the equivalence symbols aligned use && for the second equivalence:

\begin{alignat}{2}
x& = y_1-y_2+y_3-y_5+y_8-\dots
&\quad& \text{by \eqref{eq:C}}\\
& = y’\circ y^* && \text{by \eqref{eq:D}}\\
& = y(0) y’
&& \text {by Axiom 1.}
\end{alignat}

-

I know this has been solved for a while, but can't you just use OP's second solution with \displaystyle?

$\begin{array}{rcccl} \displaystyle\sum a &\le& \displaystyle\sum b &\le& \displaystyle\sum c \\ \displaystyle\log \sum a &\le& \displaystyle\log \sum b &\le& \displaystyle\log \sum c \end{array}$

-

In addition to each cell being in \textstyle rather than \displaystyle, the spacing around the binary operators is quite poor. Look how wide it is as compared to the correct spacing you see for the \le on the left side of the align.

Here's one way to do what you want. I don't claim it's the best though. In fact, I'm not terribly happy about it.

\newcommand*\dmath[1]{$\mathsurround0pt\displaystyle#1$}
\newlength\equationwidth
\settowidth\equationwidth{\dmath{\log\sum b}}
\begin{align*}
\sum a&\le\makebox[\equationwidth]{\dmath{\sum b}}\le\sum c\\
\log\sum a&\le\log\sum b\le\log\sum c
\end{align*}


To be clear, I think it looks fine. I'm not happy with having to manually specify lengths.

-
By the way, isn't there a way to add a stretchy \hspace inside the alignat environment? That would solve the problem would it not? –  Yossi Farjoun Oct 18 '10 at 22:22
@Yossi Farjoun: Not that I could discover. –  TH. Oct 18 '10 at 22:56

Here's one which, funnily enough, doesn't use any align.

\eqalign{ \phantom{\log}\sum a \le \phantom{\log}\sum b \le \phantom{\log}\sum c \cr \log \sum a \le \log \sum b \le \log \sum c \cr }


Which, I now realize, doesn't meet the requirements. Specifically, the centering of the \sum's. So in case I've now fully understood:

\vbox{\openup1\jot\halign{#&&\ \hfil\displaystyle#\hfil\cr &\sum a &\leq&\sum b &\leq&\sum c\cr &\log\sum a&\leq&\log\sum b&\leq&\log\sum c\cr}}

-
Well, it uses the most basic (TeX-)align, namely \eqalign ... –  Hendrik Vogt Dec 5 '10 at 11:17
@Hendrik Vogt: True. I was thinking in terms of &'s and so forth. –  morbusg Dec 5 '10 at 11:32