2

I would like to add some space, like \hspace*{3pt}, after summation symbol automatically. I could not find a command doing this?

\documentclass{article}

\begin{document}
\[
\sum_{i=1}^{n} x_i \quad \sum_{i=1}^{n} \hspace*{3pt} x_i
\]

\[
\sum x_i \quad \sum \hspace*{3pt} x_i
\]
\end{document}

Any suggestion?

Muhsin
  • 87

3 Answers3

2

You can define special macro \sum which uses the original \sum and adds the desired space:

\let\orisum=\sum
\protected\def\sum{\orisum\futurelet\next\sumA}
\def\sumA{\ifx\next_\expandafter\sumB\else\expandafter\sumE\fi}
\def\sumB_#1{_{#1}\futurelet\next\sumC}
\def\sumC{\ifx\next^\expandafter\sumD\else\expandafter\sumE\fi}
\def\sumD^#1{^{#1}\sumE}
\def\sumE{\kern3pt}

$$
  \sum x_i \quad \sum_{i=1}^{n} x_i
$$

\bye
wipet
  • 74,238
  • One more question. How can I get the same result for mtpro2 package? It seems the definition of sum is different from the usual. I have tried but could not make it. – Muhsin Nov 07 '17 at 08:32
1

\documentclass{article}

% Inspired by https://tex.stackexchange.com/questions/361493
%
% See https://tex.stackexchange.com/questions/74353 
% for other horizontal spacing macros like \quad
\newcommand{\mySum}[2]{\sum_{#1}^{#2}\quad}

\begin{document}

\begin{equation}
\mySum{i=1}{n} x_i \quad \mySum{i=1}{n}  x_i
\end{equation}

\end{document}

enter image description here

1

It's very easy with the e argument type for xparse:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\let\amsmathsum\sum

\RenewDocumentCommand{\sum}{e{_^}}{%
  \amsmathsum
  \IfValueT{#1}{_{#1}}%
  \IfValueT{#2}{^{#2}}%
  \hspace{20pt}% exaggerated to show the effect
}

\begin{document}

\begin{gather*}
\amsmathsum_{i=1}^{n} x_i % original
\\
\sum_{i=1}^n x_i % modified
\\
\sum x_i % no limits
\\
\sum_{1\le i\le n} x_i % only subscript
\\
\end{gather*}

\end{document}

With e{_^} one specifies two arguments of the form _{...} and ^{...} (in either order; if one or both are missing, \IfValueT will do nothing.

The value 20pt is exaggerated just in order to show the wanted effect is achieved.

enter image description here

egreg
  • 1,121,712