too little space between the bar on the denominator and the horizontal line
I think the problem here is that you are using inline math mode $..$
as opposed to display mode \[...\]
. Here is the comparison of the output between the two:
with the second one producing better spacing. To obtain that you need to either use one of the following
\[\frac{\bar{p}_1}{\bar{p}_1 + \bar{h}_1}\]
$\displaystyle \frac{\bar{p}_1}{\bar{p}_1 + \bar{h}_1}$
$\dfrac{\bar{p}_1}{\bar{p}_1 + \bar{h}_1}$
Note that \dfrac
requires that the amsmath
package be loaded, either by including it explictly \usepackage{amsmath}
, or as part some other package that already includes amsmath
, such \usepackage{mathtools}
.
Here is the MWE. Note that the center
environment was only used to simplify the image capture.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{center}
$\frac{\bar{p}_1}{\bar{p}_1 + \bar{h}_1}$
\end{center}
\[\frac{\bar{p}_1}{\bar{p}_1 + \bar{h}_1}\]
\begin{center}
$\displaystyle \frac{\bar{p}_1}{\bar{p}_1 + \bar{h}_1}$
\end{center}
\begin{center}
$\dfrac{\bar{p}_1}{\bar{p}_1 + \bar{h}_1}$
\end{center}
\end{document}
To make the bar wider you can use \overline
as in:
$\dfrac{\overline{p}_1}{\overline{p}_1 + \overline{h}_1}$
or adapt the xoverline
from The \bar and \overline commands with which you can adjust the spacing:
$\dfrac{\xoverline{p}_1}{\xoverline{p}_1 + \xoverline{h}_1}$
or specify you want it wider with:
$\dfrac{\xoverline[1.25]{p}_1}{\xoverline[1.25]{p}_1 + \xoverline[1.25]{h}_1}$
Here is a comparison between \bar{p}_1
, \overline{p}_1
, \xoverline[1.25]{p}_1}
, and {\xoverline[1.50]{p}_1
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newsavebox\myboxA
\newsavebox\myboxB
\newlength\mylenA
\newcommand*\xoverline[2][1.00]{%
\sbox{\myboxA}{$\m@th#2$}%
\setbox\myboxB\null% Phantom box
\ht\myboxB=\ht\myboxA%
\dp\myboxB=\dp\myboxA%
\wd\myboxB=#1\wd\myboxA% Scale phantom
\sbox\myboxB{$\m@th\overline{\copy\myboxB}$}% Overlined phantom
\setlength\mylenA{\the\wd\myboxA}% calc width diff
\addtolength\mylenA{-\the\wd\myboxB}%
\ifdim\wd\myboxB<\wd\myboxA%
\rlap{\hskip 0.5\mylenA\usebox\myboxB}{\usebox\myboxA}%
\else
\hskip -0.5\mylenA\rlap{\usebox\myboxA}{\hskip 0.5\mylenA\usebox\myboxB}%
\fi}
\makeatother
\begin{document}
$\dfrac{\bar{p}_1}{\bar{p}_1 + \bar{h}_1}$\quad
$\dfrac{\overline{p}_1}{\overline{p}_1 + \overline{h}_1}$\quad
$\dfrac{\xoverline[1.25]{p}_1}{\xoverline[1.25]{p}_1 + \xoverline[1.25]{h}_1}$
$\dfrac{\xoverline[1.50]{p}_1}{\xoverline[1.50]{p}_1 + \xoverline[1.50]{h}_1}$
\end{document}
It is possible to define your own fraction command. The amsmath
package provides
\genfrac{<ldelim>}{<rdelim>}{<thickness>}{<mathmode>}{<num>}{<denom>}
This typesets the fraction using numerator <num>
and denominator <denom>
with a line thickness <thickness>
. Left and right delimiters are possible by specifying <ldelim>
and/or <rdelim>
. The mathmode override is also possible via <mathmode>
by specifying an integer value from 0-3, which select respectively \displaystyle
, \textstyle
, \scriptstyle
, and \scriptscriptstyle
.
In the minimal example below I've defined \myfrac[<gap>]{<num>}{<denom>}
which raises/lowers <num>
/<denom>
by <gap>
using \raisebox
:
\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newcommand{\myfrac}[3][0pt]{\genfrac{}{}{}{}{\raisebox{#1}{$#2$}}{\raisebox{-#1}{$#3$}}}
\begin{document}
\centering
\verb!Text style! \par
$\frac{a}{b}\ \myfrac{a}{b}\ \myfrac[1pt]{a}{b}\ \myfrac[2pt]{a}{b}\ \myfrac[3pt]{a}{b}$
\bigskip
\verb!Display style! \par
\[\frac{a}{b}\ \myfrac{a}{b}\ \myfrac[1pt]{a}{b}\ \myfrac[2pt]{a}{b}\ \myfrac[3pt]{a}{b}\]
\end{document}
Perhaps a modification of this might suit your needs here, or elsewhere. It would also be possible to use a better choice mechanism to scale the font appropriately. However, this answer just provides a proof-of-concept.
When in inline math mode, and especially when diacritics (such as \bar{.}
) are involved, it's almost always preferable to replace an expression such as
$\frac{\bar{p}_1}{\bar{p}_1+\bar{h}_1}$
with its "inline fraction" form,
$\bar{p}_1 / (\bar{p}_1+\bar{h}_1)$
See, e.g., the TeXbook, pp. 139f., for Knuth's "endorsement" of this form for inline math usage. The two expressions look like this (deliberately enlarged to make the problem with the inline-fraction method more easily visible):
Of course, if a math expression containing fractions is in "display" format (i.e., on a line by itself), there's usually no reason or need to use the "inline fraction" form.