Custom Math Symbol - Two Sigma Sums
At its simplest, with a stack.
EDITED to preserve the math style of the \sum
s:
\documentclass{article}
\usepackage{stackengine,scalerel}
\newcommand\doublesum{\mathop{\ThisStyle{\ensurestackMath{%
\stackengine{.3ex}{\SavedStyle\,\sum}{\SavedStyle\sum}{O}{l}{F}{F}{L}}}}}
\begin{document}
\centering
\[
\doublesum_{ij}^{ND} x_{ij} = 0
\]
\(
\doublesum_{ij}^{ND} x_{ij} = 0
\)
\end{document}
One can, of course, opt to place a comma or small gap between the respective indices and upper limits. Alternately, one can employ a more complex manipulation to vertically stagger the indices, which are now passed as four mandatory arguments:
\documentclass{article}
\usepackage{stackengine,scalerel,amsmath}
\newcommand\doublesum[4]{\ThisStyle{\ensurestackMath{\mathop{%
{\stackengine{.3ex}{\SavedStyle\,\sum}{\SavedStyle\sum}{O}{l}{F}{F}{L}}}
_{\stackengine{.3ex}{\SavedStyle_{\phantom{#1}#2}}{%
\SavedStyle_{#1}}{O}{l}{F}{F}{L}}
^{\stackengine{.3ex}{\SavedStyle_{#3}}{%
\SavedStyle_{\phantom{#3}#4}}{U}{l}{F}{F}{L}}}}}
\begin{document}
\centering
\[
\doublesum{i}{j}{N}{D} x_{ij} = 0
\]
\(
\doublesum{i}{j}{N}{D} x_{ij} = 0
\)
\end{document}
The output is horrible, in my opinion.
\documentclass{article}
\usepackage{amsmath}
\makeatletter
% the user level command, respecting options to amsmath such as 'nosumlimits'
\newcommand\doublesum{\DOTSB\doublesum@\slimits@}
% the lower level command, robust so it won't break in moving arguments
\DeclareRobustCommand{\doublesum@}{%
\mathop{%
\vphantom{\sum@}% the same dimensions as \sum
\smash{\mathpalette\doublesum@@\relax}% delegate to \mathpalette
}%
}
% the preceding command delegates to \mathpalette
\newcommand{\doublesum@@}[2]{%
% vertically center the whole
\vcenter{\hbox{%
% \ooalign superimposes the rows (separated by \cr)
\ooalign{%
% first row with some more space on the right
$\m@th#1\sum@\doublesum@kern{#1}$\cr
% a vertical adjustment based on the current math style
\noalign{%
\sbox\z@{$\m@th#1\mkern2mu$}%
\kern\wd\z@
}
% second row with some more space on the left
$\m@th#1\doublesum@kern{#1}\sum@$\cr
}%
}}%
}
\newcommand{\doublesum@kern}[1]{%
% the kern should be greater in \displaystyle
\mkern\ifx#1\displaystyle 4\else 2\fi mu
}
\makeatother
\begin{document}
$
\displaystyle\doublesum_{i,j}^{N}
\textstyle\doublesum_{i,j}^{N}
\scriptstyle\doublesum_{i,j}^{N}
\scriptscriptstyle\doublesum_{i,j}^{N}
$
$\displaystyle\doublesum_{i,j}^{N}\sum_{i,j}^{N}$
\end{document}
See The mysteries of \mathpalette for more information on \mathpalette
As usual, I prefer going the good ol’ ways: here is a classical solution with \mathpalette
. It has now been updated to improve integration with the amsmath
package: it is for me a pleasure to thank @egreg both for having reminded me of this and for having allowed me to copy some code from his excellent (as always!) answer.
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\usepackage{amsmath} % even if it not strictly necessary...
\makeatletter
\newcommand*\doublesum{\DOTSB\doublesum@x}
\DeclareRobustCommand*\doublesum@x{\mathop{\mathpalette\doublesum@y{}}\slimits@}
\newcommand*\doublesum@y[2]{%
\vcenter{%
\setbox\z@ \hbox{$\m@th #1\sum$}%
\baselineskip .2\ht\z@
\lineskiplimit -\maxdimen
\copy\z@
\moveright .2\wd\z@ \box\z@
}
}
\makeatother
% Check robustness:
\typeout{\doublesum.} % expected output: "\DOTSB \doublesum@x ."
\begin{document}
Text before.
\[
\doublesum_{ij}^{ND} x_{ij} \neq \sum_{ij}^{ND} x_{ij}
\]
Text after: \( \doublesum_{ij}^{ND} x_{ij} = 0 \).
Now in \verb|\scriptstyle|: \( \frac{\doublesum_{i\in I} x_{i}}{2} \).
\end{document}
This is what I get in print: