How do I get \nicefrac
or \xfrac
work in \displaystyle
, i.e., without reducing the font size?
2 Answers
As an alternative (since \nicefrac
and \sfrac
do not seem to be adjustable to representing digits in displaystyle)...
Adjusting my answer from Modifying fraction macro for in-line text and exponents, this will also set numerator and denominator as text if called in text mode, and as math in math mode.
\documentclass{article}
\usepackage{graphicx}
\newcommand{\altfrac}[2]{\ifmmode\def\tmp{$}\else\def\tmp{}\fi\mbox{%
{\raisebox{.24\ht\strutbox}{\tmp#1\tmp}}%
\kern-2.2pt\scalebox{1.6}[1.5]{/}\kern-1.8pt%
{\tmp#2\tmp}%
}}
\begin{document}
\parindent 0pt
This is \texttt{altfrac:}\qquad
\altfrac{12}{14} \altfrac{31415}{27182} \altfrac{abc}{def} \altfrac{Foo!}{Bar?}
\altfrac{\#\$\%+/<>=}{?\@[]\textbackslash\_|\{\}§†}
\[\left(\frac{3x}{2y}\right)^{\altfrac{3}{2}}=\altfrac{\lambda}{2x}\]
\qquad And here is \altfrac{x}{y} versus $\altfrac{x}{y}$\\
\end{document}
WARNING: if used in inline mode, the size of the /
will possibly cause the line spacing to temporarily adjust. While this can be eliminated by \smash
'ing the \scalebox
, that could result in glyph overlap.
Using \Large
before is doing the trick :
\text{\Large$\sfrac{1}{10}$}
It's not a proper solution and more just a hack since it produces a warning (Font: Size substitution...) and it's has to be manually specified.
Here is a minimal example:
\documentclass[varwidth,margin=0.5cm]{standalone}
\usepackage{xfrac}
\begin{document}
\begin{itemize}
\item $\frac{1}{10} =\sfrac{1}{10}$
\item $\displaystyle\frac{1}{10} = \text{\Large$\sfrac{1}{10}$}$
\end{itemize}
\end{document}
And the corresponding output: