I want a fraction like nicefrac, but with normal size denominator and numerator. Is there a package for that?
[Tex/LaTex] Are there alternatives to nicefrac that does not shrink numerator and denominator
math-mode
Related Solutions
As illustrated in the highest-voted answer to Align denominator of fraction to left, \hfill
will do the trick.
Here's a macro, \myfrac
, that puts the \hfill
either in the numerator or the denominator as necessary
\newcommand{\myfrac}[2]{%
\setbox0\hbox{$#1$} % put the numerator in box0
\dimen0=\wd0 % measure box0
\setbox1\hbox{$#2$} % put the denominator in box1
\dimen1=\wd1 % measure box1
\ifdim\wd0<\wd1 % if box0 is narrower than box1
\dfrac{#1\hfill}{#2} % put \hfill in the numerator
\else
\dfrac{#1}{#2\hfill} % otherwise put \hfill in the denominator
\fi
}
Complete MWE
\documentclass{article}
\usepackage{amsmath}
\newcommand{\myfrac}[2]{%
\setbox0\hbox{$#1$} % put the numerator in box0
\dimen0=\wd0 % measure box0
\setbox1\hbox{$#2$} % put the denominator in box1
\dimen1=\wd1 % measure box1
\ifdim\wd0<\wd1 % if box0 is narrower than box1
\dfrac{#1\hfill}{#2} % put \hfill in the numerator
\else
\dfrac{#1}{#2\hfill} % otherwise put \hfill in the denominator
\fi
}
\begin{document}
\begin{itemize}
\item[Original] $\dfrac{(x_i - x)^{N+1}}{(N+1)!}$
\item[Test 1] $\myfrac{(x_i - x)^{N+1}}{(N+1)!}$
\item[Test 2] $\myfrac{(N+1)!}{(x_i - x)^{N+1}}$
\end{itemize}
\end{document}
When TeX is in display-style math mode and the amsmath
package is loaded, \frac
and \dfrac
are equivalent, and the material in the numerator and denominator portions of \frac
will be typeset in "text-style math" mode by default. This entails, among other things, that summation and integral symbols will be typeset in text style, as will any fractional expressions. The resulting tight, or "cramped", look is probably what you're looking to avoid.
To override the default setting, i.e., to force TeX to render the material in both the numerator and denominator terms in display-style math mode, one needs to insert an explicit \displaystyle
instruction at the start of both the numerator and denominator material. For more on this subject, see the posting Show inline math as if it were display math.
If you have a lot of these expressions, it's worthwhile to create a macro called, say, \ddfrac
(short for "double displaystyle frac", I suppose):
\newcommand\ddfrac[2]{\frac{\displaystyle #1}{\displaystyle #2}}
\documentclass[12pt]{article}
\usepackage{amsmath}
\newcommand\ddfrac[2]{\frac{\displaystyle #1}{\displaystyle #2}}
\begin{document}
\begin{align*}
\frac{\sum_{i=1}^\infty \frac{1}{i^2}}{ \int_{-\infty}^\infty
\frac{1}{\sqrt{2\pi\sigma^2}} \exp\bigl(-\frac{(x-\mu)^2}{2\sigma^2}\bigr)
\,\mathrm{d}x} &= \frac{\pi^2}{6}
\qquad\text{too cramped?}\\[2ex]
\ddfrac{\sum_{i=1}^\infty \frac{1}{i^2}}{\int_{-\infty}^\infty
\frac{1}{\sqrt{2\pi\sigma^2}} \exp\biggl(-\frac{(x-\mu)^2}{2\sigma^2}\biggr)
\,\mathrm{d}x} &= \frac{\pi^2}{6}
\qquad\text{about right?}
\end{align*}
\end{document}
Best Answer
Here is a definition that does not shrink either and that you can modify to your taste: