Is there a way to make \frac{}{}
bigger? By default looks like all equations keep the same size. That means if I write x=\frac{a}{b}
x has the right size, while frac is a little bit smaller. I want that x
, numerator and denominator keep the same size.
[Tex/LaTex] Make numerator and denominator terms of \frac bigger
equationsfractions
Related Solutions
I though this was an interesting question, so I gave it a try.
Let me start off with the result:
main.tex
:
\documentclass{article}
\usepackage{wfrac}
\begin{document}
\setmaxeq{a+b} % Reference equation for size
\[ \wfrac{x}{2} \]
\[ \wfrac{x+y}{2} \]
\[ \wfrac{\sum_{i=1}^{N} i^3}{x+y+z+t} \]
\[ \wfrac{\sum_{i=1}^{N} i^3}{\sum_{i=1}^{N} i} \]
\setmax{34pt}{10pt} % Manual maximum size
\[ \wfrac{\sum_{i=1}^{N} i^3}{\sum_{i=1}^{N} i} \]
\setmaxeq{x} % Reference equation again
\[ \wfrac{x}{x} \]
\[ \efrac{x}{x} \]
\end{document}
And it looks like this:
Options:
text
: compare to the equation in\textstyle
.display
: compare to the equation in\displaystyle
.none
: compare to the equation in whatever style is currently active.noparen
: no parenthesessmall
: small maximum height and widthbig
: big maximum height and widthhuge
: huge maximum height and widthlparen
: set left paren, eg:lparen=\left[
rparen
: set right paren, eg:rparen={\right]}
div
: set division mark, eg:div=\div
Commands
\wfrac
: fraction following 'less' rules.\efrac
: fraction following 'less or equal' rules.\setmax
: set the maximum size.\setmaxeq
: set the maximum size using a reference equation.\getmax
: get the maximum size.\getsize
: get the size from an equation.\setparen
: set the parentheses, takes two arguments.\setdiv
: set the division mark.
And here is wfrac.sty
:
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{wfrac}[2012/11/03 v1.01 intelligent fractions]
% Lengths and widths
\newdimen \wfrac@hx
\newdimen \wfrac@hy
\newdimen \wfrac@hmax
\newdimen \wfrac@wx
\newdimen \wfrac@wy
\newdimen \wfrac@wmax
\newdimen \wfrac@wmaxcalc
% Parenthesis and division mark
\newcommand*{\wfrac@lparen}{\left(}
\newcommand*{\wfrac@rparen}{\right)}
\newcommand*{\wfrac@div}{\middle/}
% Options
\IfFileExists{xkeyval.sty}{
\RequirePackage{xkeyval}
\DeclareOptionX{lparen}{\renewcommand*{\wfrac@lparen}{##1}}
\DeclareOptionX{rparen}{\renewcommand*{\wfrac@rparen}{##1}}
\DeclareOptionX{div}{\renewcommand*{\wfrac@div}{##1}}
}{
\let\DeclareOptionX\DeclareOption
\let\ExecuteOptionsX\ExecuteOptions
\let\ProcessOptionsX\ProcessOptions
}
\DeclareOptionX{text}{\edef\wfrac@style{\textstyle}}
\DeclareOptionX{display}{\edef\wfrac@style{\displaystyle}}
\DeclareOptionX{none}{\edef\wfrac@style{}}
\DeclareOptionX{noparen}{\renewcommand*{\wfrac@lparen}{}\renewcommand*{\wfrac@rparen}{}}
\DeclareOptionX{small}{\wfrac@wmax = 25pt \wfrac@hmax = 10pt}
\DeclareOptionX{big}{\wfrac@wmax = 50pt \wfrac@hmax = 50pt}
\DeclareOptionX{huge}{\wfrac@wmax = 100pt \wfrac@hmax = 100pt}
\ExecuteOptionsX{text,small}
\ProcessOptionsX\relax
% Fraction variations
\newcommand*{\wfrac@Afrac}[2]{\left. \wfrac@lparen #1 \wfrac@rparen \wfrac@div \wfrac@lparen #2 \wfrac@rparen \right.}
\newcommand*{\wfrac@Bfrac}[2]{\frac{1}{#2}\wfrac@lparen #1 \wfrac@rparen}
\newcommand*{\wfrac@Cfrac}[2]{\frac{#1}{#2}}
% Main commands
\newcommand*\setparen[2]{
\renewcommand*{\wfrac@lparen}{#1}
\renewcommand*{\wfrac@rparen}{#2}
}
\newcommand*\setdiv[1]{
\renewcommand*{\wfrac@div}{#1}
}
\newcommand*\setmax[2]{
\wfrac@wmax = #1
\wfrac@hmax = #2
}
\newcommand*\setmaxeq[1]{
\settowidth{\wfrac@wmax}{$ \wfrac@style #1 $}
\settoheight{\wfrac@hmax}{$ \wfrac@style #1 $}
}
\newcommand*\getmax{
\the\wfrac@wmax $\times$ \the\wfrac@hmax
}
\newcommand*\getsize[1]{
\settowidth{\wfrac@wx}{$ \wfrac@style #1 $}
\settoheight{\wfrac@hx}{$ \wfrac@style #1 $}
\the\wfrac@wx $\times$ \the\wfrac@hx
}
\newcommand*\wfrac[2]{
\settowidth{\wfrac@wx}{$ \wfrac@style #1 $}
\settowidth{\wfrac@wy}{$ \wfrac@style #2 $}
\settoheight{\wfrac@hx}{$ \wfrac@style #1 $}
\settoheight{\wfrac@hy}{$ \wfrac@style #2 $}
% max(w0, 2 * wy)
\ifdim \wfrac@wmax < 2\wfrac@wy
\wfrac@wmaxcalc = 2\wfrac@wy
\else
\wfrac@wmaxcalc = \wfrac@wmax
\fi
%
\ifdim \wfrac@hy < \wfrac@hmax
\ifdim \wfrac@wy < \wfrac@wmax
\ifdim \wfrac@hx < \wfrac@hmax
\ifdim \wfrac@wx < \wfrac@wmaxcalc
\let\wfrac@frac=\wfrac@Cfrac
\else
\let\wfrac@frac=\wfrac@Bfrac
\fi
\else
\let\wfrac@frac=\wfrac@Bfrac
\fi
\else
\let\wfrac@frac=\wfrac@Afrac
\fi
\else
\let\wfrac@frac=\wfrac@Afrac
\fi
%
\wfrac@frac{#1}{#2}
}
\newcommand*\efrac[2]{
\settowidth{\wfrac@wx}{$ \wfrac@style #1 $}
\settowidth{\wfrac@wy}{$ \wfrac@style #2 $}
\settoheight{\wfrac@hx}{$ \wfrac@style #1 $}
\settoheight{\wfrac@hy}{$ \wfrac@style #2 $}
% max(w0, 2 * wy)
\ifdim \wfrac@wmax < 2\wfrac@wy
\wfrac@wmaxcalc = 2\wfrac@wy
\else
\wfrac@wmaxcalc = \wfrac@wmax
\fi
%
\ifdim \wfrac@hy > \wfrac@hmax
\let\wfrac@frac=\wfrac@Afrac
\else
\ifdim \wfrac@wy > \wfrac@wmax
\let\wfrac@frac=\wfrac@Afrac
\else
\ifdim \wfrac@hx > \wfrac@hmax
\let\wfrac@frac=\wfrac@Bfrac
\else
\ifdim \wfrac@wx > \wfrac@wmaxcalc
\let\wfrac@frac=\wfrac@Bfrac
\else
\let\wfrac@frac=\wfrac@Cfrac
\fi
\fi
\fi
\fi
%
\wfrac@frac{#1}{#2}
}
\endinput
A couple of versions, you probably need to fiddle with the spacing to get exactly what you need but:
\documentclass{article}
\def\cFrac#1#2{%
\begin{array}{@{}c@{}}\multicolumn{1}{c|}{#1}\\%
\hline\multicolumn{1}{|c}{#2}\end{array}}
\def\cFracB#1#2{%
\vcenter{\hbox{\strut$#1$\,\vrule}\hrule\hbox{\strut\vrule\,$#2$}}}
\begin{document}
$ A + \cFrac{B}{C} + \cFrac{D}{E}$.
$ A + \cFracB{B}{C} + \cFracB{D}{E}$.
\end{document}
Best Answer
I assume your document is in inline math mode when the fraction occurs.
While in inline math mode, the numerator and denominator of
\frac
are set in\scriptstyle
by default. Script-size letters and symbols are about 30% (linearly) smaller than in text size.To force TeX to typeset the numerator and denominator terms in
\textstyle
, either prefix the\displaystyle
directive to\frac
or -- if theamsmath
package is loaded -- write\dfrac
.If you want to typeset the numerator and denominator terms in
\displaystyle
(which may be necessary if you have "large" math symbols such as\sum
and\prod
), it's best to set up a dedicated macro called, say,\ddfrac
to perform the job.