2

The default vertical spacing for fractions accommodates the possibility of a character with a descender or an ascender (or the possibility of subscripts/superscripts). This is, for the most part, the desirable functionality. For example, in the code below,

$$\frac{g}{a}=\frac{a}{c}=\frac{a}{b}$$

nothing needs to be changed. However, there is occasion where an expression like the ones below

$$\frac{a}{c}$$
$$\frac{a}{b}$$
$$\frac{b}{a}$$

occurs in isolation where a reduction in the vertical space on either side, or both, seems warranted to balance the fraction.

If I'm going on a final pass through a document, what would be the best approach to remove this vertical space that would be compatible with a change of font?

3
  • Apart from don't: you write your own macro that typesets numerator and denominator inside boxes and measures it, then draw your own version of a fraction that only uses those sizes and no \strut or similar.
    – Skillmon
    Commented Jan 21, 2019 at 20:21
  • 1
    See Why is \[ ... \] preferable to $$ ... $$?
    – Werner
    Commented Jan 21, 2019 at 21:04
  • @Werner I excluded amsmath on purpose.
    – user45054
    Commented Jan 21, 2019 at 21:44

2 Answers 2

3

I'm not sure it's a good idea. Anyhow, here's an implementation that should only be used in displays (fractions in text style or lower are already adjusted).

\documentclass{article}
\usepackage{amsmath}

\newcommand{\afrac}[2]{%
  \dfrac{\adjustbot{#1}}
        {\adjusttop{#2}}%
}

\makeatletter
\newcommand{\adjustbot}[1]{%
  \begingroup
  \settodepth\dimen@{$\textstyle y$}%
  \raisebox{\dimexpr\depth-\dimen@}{$\m@th\textstyle#1$}%
  \endgroup
}
\newcommand{\adjusttop}[1]{%
  \begingroup
  \settoheight\dimen@{$\textstyle l$}%
  \raisebox{\dimexpr\dimen@-\height}{$\m@th\textstyle#1$}%
  \endgroup
}
\makeatother

\begin{document}

\[
\frac{a}{b}\afrac{a}{b}\quad
\frac{a}{c}\afrac{a}{c}\quad
\frac{b}{a}\afrac{b}{a}\quad
\frac{g}{a}\afrac{g}{a}
\]
\end{document}

enter image description here

2
\documentclass{article}
\newcommand{\myfrac}[2]
{\frac{\raisebox{-.4ex}{$#1$}}{\raisebox{.4ex}{$#2$}}}
\begin{document}
$$\frac{p}{d}=\myfrac{a}{c}$$
$$\frac{p}{d}=\myfrac{a}{b}$$
$$\frac{p}{d}=\myfrac{b}{a}$$
\end{document}

enter image description here

You must log in to answer this question.