Why smashing a sum change an horizontal spacing?
You asked,
How can I smash the
\sum
without changing the horizontal spacing around it?
To \smash
the expression without affecting the spacing between \frac{1}{N}
and \sum
, insert an empty math atom -- {}
-- as the first element of the argument of \smash
. For instance,
\bar{x} = \frac{1}{N}\smash{{}\sum_{n=1}^N x_i}
A full MWE:
\documentclass[11pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern,microtype,mathtools,amssymb}
\begin{document}
\hrule
\[
\bar{x} = \frac{1}{N} \sum_{n=1}^N x_i %% without \smash
\]
\hrule
\medskip
\hrule
\[
\bar{x} = \frac{1}{N} \smash{{}\sum_{n=1}^N x_i}
\]
\hrule
\medskip
\hrule
\[
\bar{x} = \smash{\frac{1}{N} \sum_{n=1}^N x_i} %% too extreme, right?
\]
\hrule
\end{document}
There are cases where a very high or deep object is better smashed; for instance, in an alignment where a formula ends with a summation and the next is much shorter, we can save vertical space by using \smash[b]{...}
around the summation. Also your case can take advantage of smashing because of the short lines of text around the display.
However, one has to be aware that \smash
(with or without the optional argument, for which one needs amsmath
) always makes an ordinary atom. The nature of the object can be reinstated with the appropriate command, in this case \mathop
.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\noindent
Blablabla bla bla blabla blaaaa.
\begin{equation}
x = \frac{1}{2} \mathop{\smash{\sum_{n=1}^N}} x.
\end{equation}
Blablabla bla bla blabla blaaaa.
\begin{equation}
x = \frac{1}{2} \sum_{n=1}^N x.
\end{equation}
Blablabla bla bla blabla blaaaa.
\end{document}
Note that the x
should go outside \smash
.
In this particular case you might decide to smash also the fraction and the input can be simplified:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\noindent
Blablabla bla bla blabla blaaaa.
\begin{equation}
x = \smash{\frac{1}{2} \sum_{n=1}^N x}.
\end{equation}
Blablabla bla bla blabla blaaaa.
\begin{equation}
x = \frac{1}{2} \sum_{n=1}^N x.
\end{equation}
Blablabla bla bla blabla blaaaa.
\end{document}
Be careful and do this refinements only when the document is in final-no-more-changes-to-the-text-I-mean-really-really-final state.