Minus sign not aligning with fraction

1,279

Solution 1

The cause of the misalignment is that the minus sign is in scriptstyle, but the fraction is being forced into displaystyle. Here are a few options:

\[e^{\displaystyle -\frac{(x-\mu_2)^2}{2\sigma^2_2}}\]

enter image description here

\[e^{\dfrac{-(x-\mu_2)^2}{2\sigma^2_2}}\]

enter image description here

\[e^{-(x-\mu_2)^2/2\sigma^2_2}\]

enter image description here

\[\exp\bigl(-(x-\mu_2)^2/2\sigma^2_2\bigr)\]

enter image description here

Solution 2

Let's consider five separate typographic approaches to displaying the expression at hand:

  • e^{-\dfrac{(...)}{...}} and e^{\dfrac{-(...)}{...}}

  • e^{-\tfrac{(...)}{...}} and e^{\tfrac{-(...)}{...}}

  • e^{-(x-\mu_2)^2/(2\sigma_2^2)} (inline-style fraction in exponent)

  • \exp(-\dfrac{...}{...}) and \exp(-\tfrac{...}{...})

  • \exp\bigl(-(x-\mu_2)^2/(2\sigma_2^2)\bigr) (inline-style fraction)

enter image description here

I think we may posit that the expressions in the first two rows look awful. (Ok, row 1 is truly awful, whereas row 2 is just plain awful.) If you must use e^{...} notation, then do please consider using the inline-fraction variant in row 3. That said, I'd really, really recommend that you consider adopting \exp(...) notation; cf. rows 4 and 5.

\documentclass{article} % or some other suitable document class
\usepackage{amsmath} % for 'gather*' env.
\begin{document}
\begin{gather*}
e^{-\dfrac{(x-\mu_2)^2}{2\sigma_2^2}} \qquad
e^{\dfrac{-(x-\mu_2)^2}{2\sigma_2^2}} \\[\jot]
e^{-\tfrac{(x-\mu_2)^2}{2\sigma_2^2}} \qquad
e^{\tfrac{-(x-\mu_2)^2}{2\sigma_2^2}} \\[\jot]
e^{-(x-\mu_2)^2/(2\sigma_2^2)}        \\[\jot]
\exp\biggl(-\frac{(x-\mu_2)^2}{2\sigma_2^2}\biggr) \qquad
\exp\Bigl(-\tfrac{(x-\mu_2)^2}{2\sigma_2^2}\Bigr) \\[\jot]
\exp\bigl(-(x-\mu_2)^2/(2\sigma_2^2)\bigr)
\end{gather*}
\end{document}

Solution 3

If you want necessarily to use \dfrac with the minus sign you add \ooalign.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools,amssymb}
\begin{document}
\[e^{-\frac{(x-\mu_2)^2}{2\sigma^2_2}}\]
\[e^{\ooalign{$-$}\dfrac{(x-\mu_2)^2}{2\sigma^2_2}}\]
\end{document}

Addendum: Using the comment of @campa with \hbox you obtain the same result.

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools,amssymb}
\begin{document}
\[e^{-\frac{(x-\mu_2)^2}{2\sigma^2_2}}\]
\[e^{\hbox{$-$}\dfrac{(x-\mu_2)^2}{2\sigma^2_2}}\]
\end{document}

enter image description here

Update 2022-04-14

Based on the discussions from this question, I propose to use \mbox instead of \hbox.

The main difference is that using \hbox in LaTeX can lead to unexpected results. So always use the latter, unless you know what you're doing with \hbox. -- egreg

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools,amssymb}
\begin{document}
default: \[e^{-\frac{(x-\mu_2)^2}{2\sigma^2_2}}\]
hbox: \[e^{\hbox{$-$}\dfrac{(x-\mu_2)^2}{2\sigma^2_2}}\]
mbox: \[e^{\mbox{$-$}\dfrac{(x-\mu_2)^2}{2\sigma^2_2}}\]
\end{document}

enter image description here

Share:
1,279

Related videos on Youtube

zmkm
Author by

zmkm

Updated on August 01, 2022

Comments

  • zmkm
    zmkm over 1 year

    When I use subscripts and superscript with \frac the numerator and denominator looks very tight,

    \documentclass[a4paper,12pt]{article}
    \usepackage{mathtools,amssymb}
    
    
    \begin{document}
    \[e^{-\frac{(x-\mu_2)^2}{2\sigma^2_2}}\]
    \[e^{-\dfrac{(x-\mu_2)^2}{2\sigma^2_2}}\]
    \end{document}
    

    enter image description here

    So I tried using \dfrac but not the minus sign and fraction line are not aligned.

    enter image description here

    Anybody has a smart fix to this?

    • David Carlisle
      David Carlisle over 1 year
      please always provide a complete test file so people can see the issue and test answers. \dfrac in a superscript is probably excessive, you could set the whole superscript, including the - in \displaystyle rather than the default \scriptstyle or use \exp notion rather than e^{..} so the expression is not in a superscript
    • James K
      James K over 1 year
      My preference would be to move the minus sign to the numerator: \frac{-(...)}{...}
  • campa
    campa over 1 year
    I hope I don't sound too blunt, but \ooalign isn't doing anything useful here. A simple \hbox would do.
  • Sebastiano
    Sebastiano over 1 year
    @campa No, don't worry. I have only seen that it worked and I have used \ooalign :-(
  • Ben Voigt
    Ben Voigt over 1 year
    Note that it's unclear whether the vertical alignment is correct in the last example, because the minus sign is altogether missing.
  • Sandy G
    Sandy G over 1 year
    @BenVoigt, there is no issue with the alignment in the last expression since there is a common baseline and only one style. But I added the missing minus sign.
  • Dr. Manuel Kuehner
    Dr. Manuel Kuehner over 1 year
    @campa and Sebastiano Please see my edit. I hope that you are ok with it.
  • Sebastiano
    Sebastiano over 1 year
    @Dr.ManuelKuehner You're always welcome......all the end of my life.