# [Tex/LaTex] Alignment of fractions of the form (a-b)/(c-d)

fractionshorizontal alignment

The fraction \frac{num}{den} are usually rendered by centering the numerator and the denominator.

Unfortunately, I find the result in the following MWE quite ugly:

\documentclass{article}

\begin{document}

If $r\neq 1$, then

$\sum_{k=0}^nr^k = \frac{1-r^{n+1}}{1-r}$

\end{document}


Indeed, the $r^{n+1}$ part is too big. I wish that the two – signs of a fraction of the form \frac{a-b}{c-d} to be vertically aligned (whatever the size of a,b,c and d) at the center of the fraction, in order to show the symmetry of the formula.

How can I get such a result?

Note: if it matters for the answer, I would like the alignment to work also for inline maths mode.

If you really think this is what you want, here's the \diffratio macro:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\diffratio}{%
\frac
{\diffratio@left{#1}{#3}-\diffratio@right{#2}{#4}}
{\diffratio@left{#3}{#1}-\diffratio@right{#4}{#2}}%
}

\newcommand{\diffratio@left}{%
\mathpalette\diffratio@left@i{{#1}{#2}}%
}
\newcommand{\diffratio@right}{%
\mathpalette\diffratio@right@i{{#1}{#2}}%
}
\newcommand\diffratio@left@i{%
\diffratio@measure{#1}{#2}%
\hb@xt@\dimen@{\hss\box\z@}%
}
\newcommand\diffratio@right@i{%
\diffratio@measure{#1}{#2}%
\hb@xt@\dimen@{\box\z@\hss}%
}
\newcommand\diffratio@measure{%
\sbox\z@{$\m@th#1\@firstoftwo#2$}%
\sbox\tw@{$\m@th#1\@secondoftwo#2$}%
\dimen@=\wd\z@
\ifdim\wd\tw@>\dimen@ \dimen@=\wd\tw@\fi
}
\makeatother

\begin{document}

\begin{gather*} I have no doubt whatsoever that the normal \frac way is better.