[Tex/LaTex] Align numerator and denominator of a fraction

alignfractions

How do I align the numerator and denominator of a fraction? I am looking for something that achieves the following psuedocode:

\frac{a^2 & b}{c & d}

(The b and d should be aligned vertically on top of one another.)

Best Answer

If you also want a on top of c, you can simply add a \hfill between c and d.

MWE:

\documentclass{article}

\begin{document}
\[
\frac{a^2 b}{c\hfill d}
\]
\end{document} 

enter image description here

If, instead, you want a^2 on top of c, also add a \hfill before c:

MWE:

\documentclass{article}

\newlength\mylength
\settowidth\mylength{$a^2$}

\begin{document}
\[
\frac{a^2 b}{\hfill c\hfill d}
\]
\end{document} 

enter image description here

Here's a last possibility, but I don't think it is what you are looking for.

\documentclass{article}

\newlength\mylength
\settowidth\mylength{$a^2$}

\begin{document}
\[
\frac{a^2 b}{\hfill c d}
\]
\end{document} 

enter image description here

Related Question