37

How do you make script-sized fractions in display mode?

In certain cases, I find that \frac-based fractions are too large for my tastes in displayed formulae. For example, I feel that the fractions here stand out way too much compared to the exponents:

standard display style

I can hack a workaround by writing things like \frac{_1}{^{24}}, but that seems like too much trouble. The result, however, does look more like what I want:

hacked display style

Alternatively, I can force text styling by writing things like {\textstyle\frac{1}{24}}. This feels cleaner to me, but I'm not sure it looks as readable as the earlier hacked version because the fractions are tighter vertically (great for text mode but a bit much for display mode).

display mode using textstyle

What would you do?

\documentclass{minimal}
\begin{document}

\[ \cos x = \sum_{n=0}^\infty \frac{(-1)^n}{(2n)!} x^{2n}
= 1 - \frac{1}{2}x^2 + \frac{1}{24}x^4 - \frac{1}{720}x^6 + \cdots \]

\[ \cos x = \sum_{n=0}^\infty \frac{(-1)^n}{(2n)!} x^{2n}
= 1 - \frac{_1}{^2}x^2 + \frac{_1}{^{24}}x^4 - \frac{_1}{^{720}}x^6 + \cdots \]

\[ \cos x = \sum_{n=0}^\infty \frac{(-1)^n}{(2n)!} x^{2n}
= 1 - {\textstyle\frac{1}{2}}x^2 + {\textstyle\frac{1}{24}}x^4
- {\textstyle\frac{1}{720}}x^6 + \cdots \]

\end{document}
2
  • 1
    Werner gave you a good answer, and I agree with you that the smaller ones look better. Off-topic: You should as well use \dotsb instead of \cdots to obtain proper spacing of the dots. I suppose you have to load amsmath for this command.
    – yo'
    Commented Mar 1, 2012 at 15:13
  • @tohecz: I don't see any difference with the \dotsb and \cdots either at the end, or in the middle of the equation. Commented Mar 1, 2012 at 17:05

3 Answers 3

48

Use amsmath's \tfrac or \dfrac constructs to forcibly write a fraction in text or display style. In amsmath.sty, these macros are defined via \genfrac

\newcommand{\dfrac}{\genfrac{}{}{}0}
\newcommand{\tfrac}{\genfrac{}{}{}1}

with the token 0/1 setting the math style to \displaystyle/\textstyle (2 is for \scriptstyle; 3 is for \scriptscriptstyle, for what it's worth).

Here's a MWE:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{align*}
\cos x &= \sum_{n=0}^\infty \frac{(-1)^n}{(2n)!} x^{2n}
= 1 - \frac{1}{2}x^2 + \frac{1}{24}x^4 - \frac{1}{720}x^6 + \dotsb\\[2\baselineskip]
\cos x &= \sum_{n=0}^\infty \dfrac{(-1)^n}{(2n)!} x^{2n}
= 1 - \dfrac{1}{2}x^2 + \dfrac{1}{24}x^4 - \dfrac{1}{720}x^6 + \dotsb \\[2\baselineskip]
\cos x &= \sum_{n=0}^\infty \tfrac{(-1)^n}{(2n)!} x^{2n}
= 1 - \tfrac{1}{2}x^2 + \tfrac{1}{24}x^4 - \tfrac{1}{720}x^6 + \dotsb
\end{align*}
\end{document}​
7
  • Just as Werner says, these are what you're looking for.
    – yo'
    Commented Mar 1, 2012 at 15:11
  • 3
    It would be probably better to show a usage example; as it stands the answer seems to say that one has to do those definition in their file.
    – egreg
    Commented Mar 1, 2012 at 18:14
  • Wouldn't it be easier to just insert the command \textstyle to the right of the &= divider? That way, you'd also get a smaller \sum symbol, i.e., it wouldn't look nearly so overbearingly large relative to the rest of the material on the RHS of the equations.
    – Mico
    Commented Mar 1, 2012 at 21:35
  • @Mico: That's suggested by PhilippeGoutet in his answer. I think the question may have been more general than that.
    – Werner
    Commented Mar 1, 2012 at 21:38
  • 2
    A full API description may help someone: \genfrac{<left parenthesis>}{<right parenthesis>}{<fraction line thickness>}{<display / text / scriptscript>}{<top element>}{<bottom element>}.
    – Atcold
    Commented Jul 28, 2016 at 16:02
12

For optimal readability of the source code, you can just use \textstyle once and get the same result:

\documentclass{article}

\begin{document}

\[ \cos x = \sum_{n=0}^\infty \frac{(-1)^n}{(2n)!} x^{2n}
= \textstyle 1 - \frac{1}{2}x^2 + \frac{1}{24}x^4 - \frac{1}{720}x^6 + \cdots \]

\end{document}

If in another context don't want the \textstyle to propagate, you can put everything inside braces:

{\textstyle 1 - \frac{1}{2}x^2 + \frac{1}{24}x^4 - \frac{1}{720}x^6 + \cdots}

This being said, in your example, using display fractions would be more coherent as you already have one inside the sum giving the cosine. Generally, it's not a good idea to have display and text fractions so close to each other in the same equation.

2
  • 1
    I don't think you need to be too worried about limiting the scope of the \textstyle command. In an align environment, for instance, the scope of this command ends automatically at every alignment tab (&) and at every line break. :-)
    – Mico
    Commented Mar 1, 2012 at 22:07
  • 1
    Or \scriptstyle for even smaller equations (useful for inline equations) Commented Jun 29, 2015 at 6:37
7

A more general way is to use \scalebox from package graphicx and define your own macros.

enter image description here

\documentclass{minimal}
\usepackage{amsmath}
\usepackage{graphicx}
\setlength{\parskip}{\medskipamount}

\begin{document}

\def\hmath#1{\text{\scalebox{1.6}{$#1$}}}
\def\lmath#1{\text{\scalebox{1.4}{$#1$}}}
\def\mmath#1{\text{\scalebox{1.2}{$#1$}}}
\def\smath#1{\text{\scalebox{.8}{$#1$}}}

\def\hfrac#1#2{\hmath{\frac{#1}{#2}}}
\def\lfrac#1#2{\lmath{\frac{#1}{#2}}}
\def\mfrac#1#2{\mmath{\frac{#1}{#2}}}
\def\sfrac#1#2{\smath{\frac{#1}{#2}}}

\def\pow{^\mmath}

Sizes: Huge , Large , Medium , Normal , Small

Displayed fractions: $\displaystyle \hfrac{x^k}{k!} = \lfrac{x^k}{k!} = \mfrac{x^k}{k!} = \frac{x^k}{k!} = \sfrac{x^k}{k!}$

Inline fractions: $\hfrac{x^k}{k!} = \lfrac{x^k}{k!} = \mfrac{x^k}{k!} = \frac{x^k}{k!} = \sfrac{x^k}{k!}$

Displayed exponents (normal,small): $\displaystyle \frac{dy}{dx} e \pow {\frac{1}{2}\int f(x)\ dx} = \sfrac{dy}{dx} e ^ {\frac{1}{2}\int f(x)\ dx}$

Inline exponents (medium,normal): $\mfrac{dy}{dx} e \pow {\frac{1}{2}\int f(x)\ dx} = \frac{dy}{dx} e ^ {\frac{1}{2}\int f(x)\ dx}$

Displayed combinations (medium,normal): $\displaystyle \mfrac{e \pow {k\ln(x)}}{\sqrt{2\pi k}{(\mfrac{k}{e})} \pow k} = \frac{e^{k\ln(x)}}{\sqrt{2\pi k}{(\frac{k}{e})}^k}$

Inline combinations (medium,normal): $\mfrac{e \pow {k\ln(x)}}{\sqrt{2\pi k}{(\mfrac{k}{e})} \pow k} = \frac{e^{k\ln(x)}}{\sqrt{2\pi k}{(\frac{k}{e})}^k}$

Displayed series (normal): $\displaystyle \cos x = \sum_{n=0}^\infty \frac{(-1)^n}{(2n)!} x^{2n} = 1 - \frac{1}{2}x^2 + \frac{1}{24}x^4 - \frac{1}{720}x^6 + \cdots$

Displayed series (small): $\displaystyle \cos x = \smath{\sum_{n=0}^\infty} \sfrac{(-1)^n}{(2n)!} x^{2n} = 1 - \sfrac{1}{2}x^2 + \sfrac{1}{24}x^4 - \sfrac{1}{720}x^6 + \cdots$

Inline series (medium): $\cos x = \mmath\sum_{n=0}^\infty \mfrac{(-1)^n}{(2n)!} x^{2n} = 1 - \mfrac{1}{2}x^2 + \mfrac{1}{24}x^4 - \mfrac{1}{720}x^6 + \cdots$

Inline series (normal): $\cos x = \sum_{n=0}^\infty \frac{(-1)^n}{(2n)!} x^{2n} = 1 - \frac{1}{2}x^2 + \frac{1}{24}x^4 - \frac{1}{720}x^6 + \cdots$

Convergent series: $\hmath{ 1 = \dfrac{1}{2} + \smath{ \dfrac{1}{4} + \smath{ \dfrac{1}{8} + \smath{ \dfrac{1}{16} + \smath{ \dfrac{1}{32} + \smath{ \dfrac{1}{64} + \smath{ \dfrac{1}{128} } } } } } } }$

\end{document}
2
  • Excellent. I found a scalebox of 1.4 pretty good to display the PDF of a normal distribution (\frac and \dfrac left me dissatisfied): \frac{1}{\sqrt{2\sigma^2\pi}} ~ e^{\lfrac{-(x-\mu)^{2}}{2\sigma^{2}}}
    – PatrickT
    Commented Oct 23, 2017 at 8:13
  • 1
    @PatrickT: Thanks! By the way on Math SE, which does not support \scalebox, I use \def\lfrac#1#2{{\large\frac{#1}{#2}}} instead, which works even though it's invalid. The valid LaTeX would be \def\lfrac#1#2{\text{\large$\frac{#1}{#2}$}} and there are some differences compared with \mfrac. But personally I frequently use \exp for the exponential function, since I don't like having fractional exponents that are floating in the middle of thin air. =)
    – user21820
    Commented Oct 23, 2017 at 9:48

You must log in to answer this question.

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