Average sum of function

I would like to define the letter \mathbb{E} as a summation symbol for averaged sum.

I've tried the following.

\newcommand{\E}{\mathbb{E}}
$$\E_{x\in X} f(x) = \frac{1}{|X|} \sum_{x\in X}f(x)$$


The problem with this is, that the symbol \mathbb{E} and \sum are not the same size. So then I tried these options (the code isn't pretty, I know that).

\newcommand{\E}{\mathbb{E}}
$$\underset{x \in X}{\scalebox{1.5}{\E}} f(x) = \frac{1}{|X|} \sum_{x \in X} f(x).$$

$$\mathop{\scalebox{1.5}{\E}}_{x \in X} f(x) = \frac{1}{|X|} \sum_{x\in X}f(x).$$

$$\scalebox{1.5}{\E}_{x\in X} f(x) = \frac{1}{|X|} \sum_{x\in X}f(x)$$


While here \mathbb{E} is larger, it is not aligned with summation symbol (at the bottom). Also f(x) is not in the middle of E, as is in for summation symbol.

I also tried the following.

\DeclareMathOperator*{\E}{E}


This would be a nice option but it does not accept mathfonts.

Any help would be appriciated, as I am struggling with this for some while now. These are just easy examples, I use average sum a lot in my thesis so I would like to have a nice looking symbol.

• Welcome to TeX.SX! Unrelated to the question, but you shouldn't use $$...$$ for disaplyed math as explained here. Commented Jun 30, 2023 at 8:05
• Unicode has a symbol for double struck sum (U+02140 \Bbbsum). You can use that as well if you desire. Commented Jun 30, 2023 at 9:52

You can use the code in https://tex.stackexchange.com/a/23436/4427 with a suitable coefficient.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}

\makeatletter
\DeclareRobustCommand\bigop[2][1]{%
\mathop{\vphantom{\sum}\mathpalette\bigop@{{#1}{#2}}}\slimits@
}
\newcommand{\bigop@}[2]{\bigop@@#1#2}
\newcommand{\bigop@@}[3]{%
\vcenter{%
\sbox\z@{$#1\sum$}%
\hbox{\resizebox{\ifx#1\displaystyle#2\fi\dimexpr\ht\z@+\dp\z@}{!}{$\m@th#3$}}%
}%
}
\makeatother

\newcommand{\average}{\DOTSB\bigop[0.85]{\mathbb{E}}}

\begin{document}

$\average_{x\in X}f(x)=\frac{1}{|X|}\sum_{x\in X}f(x)$
\begin{center}% to show what happens inline
$\average_{x\in X}f(x)=\frac{1}{|X|}\sum_{x\in X}f(x)$
\end{center}

\end{document}


Never use  in LaTeX documents.