6

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?

1
  • 1
    Did you try \newcommand\myatop[2]{\genfrac{}{}{0pt}{}{#1\hfill}{#2\hfill}}?
    – egreg
    Feb 8, 2015 at 21:40

1 Answer 1

7

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.

3
  • Thanks, this seems to work! I accept the answer, but idly wonder why \hfill provides the desired behavior...
    – M.B.M.
    Feb 8, 2015 at 22:26
  • 2
    @M.B.M. TeX implicitly adds \hfil around numerator and denominator of a fraction, and \hfill kills it.
    – egreg
    Feb 8, 2015 at 22:27
  • Wow -- thanks for the extensive explanation!
    – M.B.M.
    Feb 9, 2015 at 2:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .