Minus sign not aligning with fraction
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}}\]
\[e^{\dfrac{-(x-\mu_2)^2}{2\sigma^2_2}}\]
\[e^{-(x-\mu_2)^2/2\sigma^2_2}\]
\[\exp\bigl(-(x-\mu_2)^2/2\sigma^2_2\bigr)\]
Solution 2
Let's consider five separate typographic approaches to displaying the expression at hand:
-
e^{-\dfrac{(...)}{...}}
ande^{\dfrac{-(...)}{...}}
-
e^{-\tfrac{(...)}{...}}
ande^{\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)
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
.
\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}
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}
Related videos on Youtube
zmkm
Updated on August 01, 2022Comments
-
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}
So I tried using
\dfrac
but not the minus sign and fraction line are not aligned.Anybody has a smart fix to this?
-
David Carlisle over 1 yearplease 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 thane^{..}
so the expression is not in a superscript -
James K over 1 yearMy preference would be to move the minus sign to the numerator: \frac{-(...)}{...}
-
-
campa over 1 yearI hope I don't sound too blunt, but
\ooalign
isn't doing anything useful here. A simple\hbox
would do. -
Sebastiano over 1 year@campa No, don't worry. I have only seen that it worked and I have used
\ooalign
:-( -
Ben Voigt over 1 yearNote that it's unclear whether the vertical alignment is correct in the last example, because the minus sign is altogether missing.
-
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 over 1 year@campa and Sebastiano Please see my edit. I hope that you are ok with it.
-
Sebastiano over 1 year@Dr.ManuelKuehner You're always welcome......all the end of my life.