6

I have created two fractions (see example below), but the denominator is a little too close to the division bar. Can I change this somehow?

\documentclass{article}
\usepackage{amsmath}

\begin{document}
    Combining two Gaussians with mean $\mu_1, \mu_2$ and variance $\sigma_1^2, \sigma_2^2$ yields a new Gaussian with mean $\mu = \frac{\sigma_2^2 \mu_1 + \sigma_1^2 \mu_2}{\sigma_1^2 + \sigma_2^2}$ and variance $\sigma^2 = \frac{1}{\frac{1}{\sigma_1^2} + \frac{1}{\sigma_2^2}}$
\end{document}
2
  • 3
    Use \dfrac instead of \frac.
    – user156344
    Mar 8, 2019 at 11:02
  • You could add a \vphantom command (for examle \vphantom{A^{A^A}}) in the beginning of each problematic dominator, and keep the style as inline math.
    – koleygr
    Mar 8, 2019 at 11:06

3 Answers 3

8

You have two main options:

  • Switch from \frac{...}{...}-notation to inline-fraction notation

  • Switch to display math to typeset the formulas for \mu and \sigma^2.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for "\text" macro
\begin{document}

\noindent
1. OP's original version:

Combining two Gaussians with mean $\mu_1, \mu_2$ and variance $\sigma_1^2, \sigma_2^2$ yields a new Gaussian with mean $\mu = \frac{\sigma_2^2 \mu_1 + \sigma_1^2 \mu_2}{\sigma_1^2 + \sigma_2^2}$ and variance $\sigma^2 = \frac{1}{\frac{1}{\sigma_1^2} + \frac{1}{\sigma_2^2}}$.

\medskip\noindent
2. Partial switch to inline-math notation

Combining two Gaussians with mean $\mu_1, \mu_2$ and variance 
$\sigma_1^2, \sigma_2^2$ yields a new Gaussian with mean 
$\mu = \frac{\sigma_2^2 \mu_1 + \sigma_1^2 \mu_2}{\sigma_1^2 + \sigma_2^2}$ 
and variance $\sigma^2 = \frac{1}{1/\sigma_1^2 + 1/\sigma_2^2}$.

\medskip\noindent
3. Full switch to inline math notation

Combining two Gaussians with means $\mu_1$ and $\mu_2$ and 
variances $\sigma_1^2$ and $\sigma_2^2$ yields a new Gaussian 
with mean $\mu = (\sigma_2^2 \mu_1 + \sigma_1^2 \mu_2)/(\sigma_1^2 + 
\sigma_2^2)$ and variance $\sigma^2 = 1/(1/\sigma_1^2 + 1/\sigma_2^2)$.

\medskip\noindent
4. Switch to display math

Combining two Gaussians with means $\mu_1$ and $\mu_2$ and 
variances $\sigma_1^2$ and $\sigma_2^2$ yields a new Gaussian 
with mean $\mu$ and variance $\sigma^2$ given by
\[
\mu=\frac{\sigma_2^2 \mu_1 + \sigma_1^2 \mu_2}{\sigma_1^2 + \sigma_2^2} 
\quad\text{and}\quad 
\sigma^2 = \frac{1}{1/\sigma_1^2 + 1/\sigma_2^2}\,.
\]

\end{document} 
4
  • \everymath{\displaystyle} would be an additional option (Just in case that the document can afford such thing.) Of course I would not use it often, but have used in special cases that looked ok. (+1)
    – koleygr
    Mar 8, 2019 at 11:23
  • 1
    @koleygr - Unless the paragraph in question is double-spaced (and hence already damaged beyond repair, typographically speaking), typesetting a \dfrac expression in running text must surely be a high crime against all known forms of decent typography. :-) If you doubt this claim, just look at the outputs of Sebastiano's and Steven's solutions...
    – Mico
    Mar 8, 2019 at 11:27
  • 1
    Thanks for the info, I also didn't like these kind of solutions but just added the comment in order to propose a more general answer for every case. But of course you are right!
    – koleygr
    Mar 8, 2019 at 11:30
  • 1
    went for the last option. Thx, Mico!
    – Luk
    Mar 8, 2019 at 11:38
5

Here, I preserve the fraction in its native \textstyle, but add a (default) 1pt buffer above and below the numerator and denominator of each fraction, which can be changed with an optional argument. I call it \qfrac[]{}{}. The MWE shows before and after.

\documentclass{article}
\usepackage{stackengine,scalerel}
\stackMath
\newcommand\qfrac[3][1pt]{\frac{%
  \ThisStyle{\addstackgap[#1]{\SavedStyle#2}}}{%
  \ThisStyle{\addstackgap[#1]{\SavedStyle#3}}%
}}
\usepackage{amsmath}

\begin{document}
    Combining two Gaussians with mean $\mu_1, \mu_2$ and variance $\sigma_1^2, 
  \sigma_2^2$ yields a new Gaussian with mean $\mu = \frac{\sigma_2^2 \mu_1 + 
  \sigma_1^2 \mu_2}{\sigma_1^2 + \sigma_2^2}$ and variance $\sigma^2 = 
  \frac{1}{\frac{1}{\sigma_1^2} + \frac{1}{\sigma_2^2}}$

   Combining two Gaussians with mean $\mu_1, \mu_2$ and variance $\sigma_1^2, 
  \sigma_2^2$ yields a new Gaussian with mean $\mu = \qfrac{\sigma_2^2 \mu_1 + 
  \sigma_1^2 \mu_2}{\sigma_1^2 + \sigma_2^2}$ and variance $\sigma^2 = 
  \qfrac[.5pt]{1}{\qfrac{1}{\sigma_1^2} + \qfrac{1}{\sigma_2^2}}$
\end{document}

enter image description here

2
  • 1
    (+1)... I would add your "1pt" inside an extra optional argument of the command.
    – koleygr
    Mar 8, 2019 at 11:18
  • Nice answer... Straightforward to the OP's problem. Welcome.
    – koleygr
    Mar 8, 2019 at 11:21
0

Alternatively, use \raisebox :

\documentclass{article}
\usepackage{amsmath}
\begin{document}
   Combining two Gaussians with mean $\mu_1, \mu_2$ and variance $\sigma_1^2, \sigma_2^2$ yields a new Gaussian with mean $\mu = \frac{\raisebox{.2in}{$\sigma_2^2 \mu_1 + \sigma_1^2 \mu_2$}}{\raisebox{-.2in}{$\sigma_1^2 + \sigma_2^2$}}$ and variance $\sigma^2 = \frac{\raisebox{.2in}{$1$}}{\raisebox{-.2in}{$\frac{1}{\sigma_1^2} + \frac{1}{\sigma_2^2}$}}$
\end{document}

result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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