[Tex/LaTex] Left justifying in \genfrac

amsmathfractions

Is there an easy way to left-justify the "numerator" and "denominator" in \genfrac? By default it centers the "numerator" and "denominator." I am using it for a custom \atop command, per suggestion here:

\newcommand\myatop[2]{\genfrac{}{}{0pt}{}{#1}{#2}}

Perhaps there is an alternative to \genfrac that provides all spacing/sizing functionality but allows one to customize justification?

Best Answer

You can use

\newcommand\myatop[2]{\genfrac{}{}{0pt}{}{#1\hfill}{#2\hfill}}

but if you want to use it under summation signs, the result will not be the best:

\documentclass{article}

\usepackage{amsmath}

\newcommand\myatop[2]{\genfrac{}{}{0pt}{}{#1\hfill}{#2\hfill}}

\begin{document}

\[
\sum_{\myatop{a}{bcd}}
\sum_{\begin{subarray}{l}a\\bcd\end{subarray}}
\sum_{1\le x\le n}
\]

\end{document}

enter image description here

You can clearly see that \myatop produces too small characters.


When TeX typesets a fraction, it determines the width w to use and eventually typesets numerator and denominator with

\hbox to w{\hfil<subformula>\hfil}

With the setting above, this will become

\hbox to w{\hfil<subformula>\hfill\hfil}

and, being \hfill “more infinite” than \hfil, it kills the two standard spacers.

You get the same behavior with

\makebox[3cm]{text\hfill}

because this has \hfil on either side (actually \hss, but it's a minor detail) and \hfil text\hfill\hfil is equivalent to text\hfill.

Related Question