Math & ScienceVertical alignment of \frac command

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
rhino7890
Posts: 10
Joined: Fri Sep 24, 2010 7:27 pm

Vertical alignment of \frac command

Post by rhino7890 »

I would like to modify the vertical alignment of the build in command \frac. Currently, the numerator floats a little too high and I would like to move it down some. I have come up with kind of a hack job by using boxes

Code: Select all

\frac{\raisebox{-2pt}{1}}{2}
which lowers the top text by 2 pts, however this messes up the formatting of the text as the \raisebox command forces the text to be the document default text size instead of the proper font size within the fraction. For example, this is especially problematic if you have a fraction in an exponent as below

Code: Select all

5^{\frac{\raisebox{-2pt}{1}}{2}}
I looked into the definition of the fraction command and it just uses TeX's \over command as follows

Code: Select all

\frac{1}{2} = \begingroup 1 \endgroup \over 2
However, I haven't been able to find the \over definition to see how that spaces everything.

So, does anyone have any ideas on how to modify the vertical alignment of the \frac command while still preserving the proper text formatting (such as in inline and displaymode)?

Thanks!
Last edited by rhino7890 on Thu Mar 24, 2011 9:54 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
rhino7890
Posts: 10
Joined: Fri Sep 24, 2010 7:27 pm

Vertical alignment of \frac command

Post by rhino7890 »

So, I found a potential solution; however, it is not as versatile as the original fraction command (although it suites my purposes). Here is the code:

Code: Select all

\renewcommand{\frac}[2]{ \mathchoice{\begingroup \raisebox{-3pt}{$\displaystyle #1$} \endgroup \over #2}{\begingroup \raisebox{-2pt}{$\scriptstyle #1$} \endgroup \over #2}{\raisebox{-2pt}{$\scriptscriptstyle #1$} \over #2}{\raisebox{-2pt}{$\scriptscriptstyle #1$} \over #2}}
Here the \mathchoice command chooses which definition to use based on the current style within mathmode. You use \mathchoice as follows: \mathchoice{formatting for displaystyle}{formatting for inline text}{formatting for subscript}{formatting for subsubscript.} Hope that helps.

Again, I would not use this definition unless you really need to (as I do).
Post Reply