Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Please see below:

enter image description here

There is too little space between the horizontal line from \frac and the bar from \bar{h_1}. So, it is a little hard to read. Any alternative way to represent the upper bar? And, it is short too.

ADDED: This is inline mode. In the display math mode, it is quite better. But in the inline math mode, it looks pretty bad, even with \bar{h}_1.

share|improve this question
1  
Can you add a minimum working example? My version of this in frac has naturally wider spaces, as you want. i.e. \frac{\bar{p}_1}{\bar{p}_1 + \bar{h}_1}. –  qubyte Nov 9 '11 at 16:10
1  
@MarkS.Everitt It was inline mode. Sorry I missed that explanation. See the added explanation. –  FEQ Nov 9 '11 at 16:22
5  
May be you could re-write your fraction as $\bar{p}_1/(\bar{p}_1 + \bar{h}_1)$ which would fit better with inline math. –  Khaled Hosny Nov 9 '11 at 16:46

5 Answers 5

up vote 13 down vote accepted

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:

enter image description here

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

enter image description here

\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}
share|improve this answer
    
Would there be any method or alternative to make the space wider, without using the displaystyle? I probably need to use another accent, like hat. –  FEQ Nov 9 '11 at 16:25
1  
See updated solution with \overline and \xoverline. –  Peter Grill Nov 9 '11 at 16:40
4  
I don't think that using \displaystyle of \dfrac in in-line math mode is a good option; it breaks the normal separation between lines. –  Gonzalo Medina Nov 9 '11 at 16:54
    
@PeterGrill: I don't think the problem is so much with the OP using inline math mode as with the fact that he/she should not be using a fraction style that's not suitable for inline math. –  Mico Nov 9 '11 at 17:01
    
This is a good answer. Very thorough. Nice. –  Seamus Nov 9 '11 at 17:05

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):

enter image description here

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.

share|improve this answer

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:

enter image description here

\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.

share|improve this answer
    
Nice addition! I always forget about \genfrac. –  Peter Grill Nov 9 '11 at 16:52

Use $\bar{h}_1$. That should at least centre the bar above h, although probably not lower it.

share|improve this answer

Use \bar{h}_1 instead. The bar doesn't belong to the subscript, just to the h.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.