# Aligning mathematical inequalities

I want to align the following at the inequality signs, however it becomes very ugly:

\begin{alignat*}{2}
\sum\limits_{i=0}^{h-1} k^i &< n &\leq \sum\limits_{i=0}^h k^i \\
\frac{k^h-1}{k-1} &< n &\leq \frac{k^{h+1}-1}{k-1} \\
\log_k(k^h-1) - \log_k(k-1) &< \log_k(n) &\leq \log_k(k^{h+1}-1) - \log_k(k-1) \\
\log_k(k^h-1) &< \log_k(n) + \log_k(k-1) &\leq \log_k(k^{h+1}-1) \\
\lceil\log_k(k^h-1)\rceil &< \lceil\log_k(n) + \log_k(k-1)\rceil &\leq \lceil\log_k(k^{h+1}-1)\rceil \\
h < \lceil\log_k(n) + \log_k(k-1)\rceil \leq h+1 \\
h-1 < \lceil\log_k(n) + \log_k(k-1)\rceil - 1 \leq h \\
h-1 < \lceil\log_k(n) + \log_k(k-1) - 1\rceil \leq h \\
\end{alignat*} 1. How can I properly format this?
• your use of alignat is incorrect. See for instance, tex.stackexchange.com/questions/49014/… Nov 17 '13 at 20:03
• You don't want to align the inequality signs, trust me. Center everything and leave some more space between lines. Nov 17 '13 at 20:40
• How do I center everything? Using \begin{center} or \centering seems to have no effect on the alignat? Nov 17 '13 at 20:45
• Why do you want to this? If you are deriving a formula, then there should be words and phrases between different parts of the derivation; displaying everything and in particular making one big alignment is no longer appropriate. Nov 18 '13 at 10:23
• @CodeKingPlusPlus, You can center all the lines by using the gather* environment from amsmath package.
– Dan
Nov 18 '13 at 18:59

\documentclass{standalone}
\usepackage{amsmath}

\begin{document}
$\begin{array}{rcl} % First line \sum\limits_{i=0}^{h-1} k^i < & n & \leq \sum\limits_{i=0}^h k^i \\[1ex] % Second line \dfrac{k^h-1}{k-1} < & n & \leq \dfrac{k^{h+1}-1}{k-1} \\[2ex] % Third line \log_k(k^h-1) - \log_k(k-1) < & \log_k(n) & \leq \log_k(k^{h+1}-1) - \log_k(k-1) \\[2ex] % Fourth line \log_k(k^h-1) < & \log_k(n) + \log_k(k-1) & \leq \log_k(k^{h+1}-1) \\[2ex] % Fifth line \lceil\log_k(k^h-1)\rceil < & \lceil\log_k(n) + \log_k(k-1)\rceil & \leq \lceil\log_k(k^{h+1}-1)\rceil \\[2ex] % Sixth line h < & \lceil\log_k(n) + \log_k(k-1)\rceil & \leq h + 1 \\[2ex] % Seventh line h - 1 < & \lceil\log_k(n) + \log_k(k-1)\rceil - 1 & \leq h \\[2ex] % Eighth line h - 1 < & \lceil\log_k(n) + \log_k(k-1) - 1\rceil & \leq h \end{array}$
\end{document} • Beautiful! This is really clean! Nov 17 '13 at 22:43
• @CodeKingPlusPlus That's exactly what I thought: the middle term in the first three lines is floating in the middle of nowhere. Nov 18 '13 at 8:30
• I was going to suggest something similar, but I would have used \begin{array}{@{}r@{}c@{}l@{}} because otherwise there is too much space. But then one has to change the first & in each row to {}&' and the second one to &{} to give the correct amount of space around the math relations.
– Dan
Nov 18 '13 at 18:56

I could understand this only if the center column expressions are horizontally centered, but then the first two lines will become unreadable.

Leave some more vertical space than the default between lines and center everything; you want a sequence of inequalities, each a consequence of the preceding line; the reader will understand this and follow without any problems. Aligning the inequality signs introduces unnecessary noise.

\documentclass{article}

\usepackage{amsmath}

\begin{document}
\begin{gather*}
\sum_{i=0}^{h-1} k^i < n \leq \sum_{i=0}^h k^i \\[1ex]
%
\frac{k^h-1}{k-1} < n \leq \frac{k^{h+1}-1}{k-1} \\[1ex]
%
\log_k(k^h-1) - \log_k(k-1) < \log_k(n) \leq \log_k(k^{h+1}-1) - \log_k(k-1) \\[2ex]
%
\log_k(k^h-1) < \log_k(n) + \log_k(k-1) \leq \log_k(k^{h+1}-1) \\[2ex]
%
\lceil\log_k(k^h-1)\rceil < \lceil\log_k(n) + \log_k(k-1)\rceil
\leq \lceil\log_k(k^{h+1}-1)\rceil \\[2ex]
%
h < \lceil\log_k(n) + \log_k(k-1)\rceil \leq h+1 \\[2ex]
%
h-1 < \lceil\log_k(n) + \log_k(k-1)\rceil - 1 \leq h \\[2ex]
h-1 < \lceil\log_k(n) + \log_k(k-1) - 1\rceil \leq h
\end{gather*}
\end{document} Is this what you're looking for? Note that I have added an extra column of &

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}

\usepackage{amsmath}

\begin{document}
\begin{alignat*}{2}
\sum\limits_{i=0}^{h-1} k^i & < n                                       &   & \leq \sum\limits_{i=0}^h k^i         \\
\frac{k^h-1}{k-1}           & < n                                       &   & \leq \frac{k^{h+1}-1}{k-1}           \\
\log_k(k^h-1) - \log_k(k-1) & < \log_k(n)                               &   & \leq \log_k(k^{h+1}-1) - \log_k(k-1) \\
\log_k(k^h-1)               & < \log_k(n) + \log_k(k-1)                 &   & \leq \log_k(k^{h+1}-1)               \\
\lceil\log_k(k^h-1)\rceil   & < \lceil\log_k(n) + \log_k(k-1)\rceil     &   & \leq \lceil\log_k(k^{h+1}-1)\rceil   \\
h                           & < \lceil\log_k(n) + \log_k(k-1)\rceil     &   & \leq h+1                             \\
h-1                         & < \lceil\log_k(n) + \log_k(k-1)\rceil - 1 &   & \leq h                               \\
h-1                         & < \lceil\log_k(n) + \log_k(k-1) - 1\rceil &   & \leq h                               \\
\end{alignat*}
\end{document}
`
• That is a lot better, but can we center the expression between the < and <= Nov 17 '13 at 20:18
• @CodeKingPlusPlus there's a question somewhere that has dealt with this before- I'll have a look... Nov 17 '13 at 21:17

If you are into the quick and easy solution, the use of an array environment is always not the 'best way' but it is a simple way to get things done. Put the entire array in a math environment, and from there put the operators in their own columns. It is fast and efficient for simple workarounds.

That being said, and as mentioned, centering would probably be the best formatting unless clarity is really the prime-goal (as it should be).