# How to create a summation symbol with a vertical bar?

I am trying to create this symbol:

I have tryed to use this:

\documentclass{article}
\usepackage{mathtools}

\makeatletter
\newcommand{\superimpose}[2]{%
{\ooalign{$#1\@firstoftwo#2$\cr\hfil$#1\@secondoftwo#2$\hfil\cr}}}
\makeatother
\newcommand{\MyTry}{\mathpalette\superimpose{{\sum}{\vert}}}

\begin{document}
$\MyTry$
\end{document}


But it doesn't do it the right way, and also i am not sure how to use put the delimeters. Thanks.

• Please always make your code compilable, by starting with \documentclass{... – hpekristiansen Aug 19 '19 at 21:58
• Sorry. Already corrected. – J.Rodriguez Aug 19 '19 at 21:59
• just curious. what does that summation symbol mean? – shamalaia Aug 20 '19 at 11:41
• @shamalaia Its just a notation that one of my proffesors use to reffer to the Aritmetic Mean – J.Rodriguez Aug 28 '19 at 5:06

Here's a mixture of \ooalign and picture mode.

\documentclass{article}
\usepackage{amsmath,pict2e}

\makeatletter
\newcommand{\barredsum}{%
\DOTSB\mathop{\mathpalette\@barredsum\relax}\slimits@
}
\newcommand{\@barredsum}[2]{%
\begingroup
\sbox\z@{$#1\sum$}%
\setlength{\unitlength}{\dimexpr2pt+\ht\z@+\dp\z@\relax}%
\@barredsumthickness{#1}%
\vphantom{\@barredsumbar}%
\ooalign{$\m@th#1\sum$\cr\hidewidth$#1\@barredsumbar$\hidewidth\cr}%
\endgroup
}
\newcommand{\@barredsumbar}{%
\vcenter{\hbox{\begin{picture}(0,1)\roundcap\Line(0,0)(0,1)\end{picture}}}%
}
\newcommand{\@barredsumthickness}[1]{% see https://tex.stackexchange.com/a/477200/
\linethickness{%
1.25\fontdimen8
\ifx#1\displaystyle\textfont\else
\ifx#1\textstyle\textfont\else
\ifx#1\scriptstyle\scriptfont\else
\scriptscriptfont\fi\fi\fi 3
}%
}
\makeatother

\begin{document}

$\barredsum_{i=1}^N x_i$

\begin{center}
$\barredsum_{i=1}^N x_{\barredsum_{i=1}^N x_{\barredsum_{i=1}^N x_i}}$
\end{center}

\end{document}


Possible improvement, where the overshoot is variable and the symbol has the same vertical extent as \sum:

\documentclass{article}
\usepackage{amsmath,pict2e,picture}

\makeatletter
\newcommand{\barredsum}{%
\DOTSB\mathop{\mathpalette\@barredsum\relax}\slimits@
}
\newcommand{\@barredsum}[2]{%
\begingroup
\sbox\z@{$#1\sum$}%
\setlength{\unitlength}{%
\dimexpr
\ifx#1\displaystyle1\else3\fi\dimexpr\@barredsumthickness{#1}\relax+
\ht\z@+\dp\z@
\relax
}%
\linethickness{\@barredsumthickness{#1}}%
\vphantom{\sum}%
\smash{\ooalign{$\m@th#1\sum$\cr\hidewidth$#1\@barredsumbar$\hidewidth\cr}}%
\endgroup
}
\newcommand{\@barredsumbar}{%
\vcenter{\hbox{\begin{picture}(0,1)\roundcap\Line(0,0)(0,1)\end{picture}}}%
}
\newcommand{\@barredsumthickness}[1]{% see https://tex.stackexchange.com/a/477200/
1.25\fontdimen8
\ifx#1\displaystyle\textfont\else
\ifx#1\textstyle\textfont\else
\ifx#1\scriptstyle\scriptfont\else
\scriptscriptfont\fi\fi\fi 3
}
\makeatother

\begin{document}

$\sum_{i=1}^N x_i \ne \barredsum_{i=1}^N x_i$

\begin{center}
$\barredsum_{i=1}^N x_{\barredsum_{i=1}^N x_{\barredsum_{i=1}^N x_i}}$
\end{center}

\end{document}


• Excuse me very much egreg. But the question is similar to this link? tex.stackexchange.com/questions/167451/average-sum-symbol?rq=1 – Sebastiano Aug 20 '19 at 21:55
• About the improved solution: instead of using \smash, which entails another \mathchoice nesting, why don’t you simply say \begin{picture}(0,0)\roundcap\Line(0,-.5)(0,.5)\end{picture}? – GuM Aug 21 '19 at 14:29
• @GuM That could be an idea. – egreg Aug 21 '19 at 16:05

To try to improve one of egreg’s answers is an exercise that is, at the same time, both enjoyable and instructive—plus, it can give bragging rights. (;-) In this case, I deem that the accepted solution is suboptimal in terms of efficiency, for the following two reasons:

1. While drawing, e.g., a witch requires the full flexibility of the picture environment, this flexibility is not needed to draw a simple line.

2. The solution uses \vphantom inside \mathpalette, which amounts to nesting \mathchoice nodes, with each of the sixteen resulting combinations containing a picture environment.

In particular, this means that the \@barredsumbar macro is executed 20 times for each invocation of the \barredsum command. People, like me, who witnessed the heroic era when LaTeX could take more than half an hour to compile a thesis are particularly sensitive to this argument.

The following code executes the \@rodriguez@overprint@bar macro only four times for each invocation of \barredsum, and relies only on TeX’s primitive rule commands to draw the line. As an added bonus, it defines also the \barredprod command, yielding a barred version of \prod: this shows how the construction can be generalized.

% 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} % the code below assumes this

\makeatletter

\newcommand*\barredsum{%
\DOTSB\mathop{%
\@rodriguez@mathpalette \@rodriguez@overprint@bar \sum
}\slimits@
}
\newcommand*\barredprod{%
\DOTSB\mathop{%
\@rodriguez@mathpalette \@rodriguez@overprint@bar \prod
}\slimits@
}

% A home-brewed version of "\mathpalette" that also supplies the font
% selector (e.g., "\textfont"):
\newcommand*\@rodriguez@mathpalette[2]{%
% #1 := macro doing the actual job, which expects as its own arguments
%         - #1, a style selector (e.g., "\displaystyle")
%         - #2, a font selector (e.g., "\textfont")
%         - #3, a custom argument (not truly necessary, here!)
% #2 := custom argument that should be passed as #3 to macro #1
\mathchoice
{#1\displaystyle      \textfont         {#2}}%
{#1\textstyle         \textfont         {#2}}%
{#1\scriptstyle       \scriptfont       {#2}}%
{#1\scriptscriptstyle \scriptscriptfont {#2}}%
}

\newcommand*\@rodriguez@overprint@bar[3]{%
% #1 := style selector (e.g., "\displaystyle")
% #2 := font selector (e.g., "\textfont")
% #3 := base symbol
\sbox\z@{$#1#3$}%
\dimen@   = \ht\z@   \advance \dimen@   \p@
\dimen@ii = \dp\z@   \advance \dimen@ii \p@
\dimen4 = 1.25\fontdimen 8 #2\thr@@ \relax
\ooalign{% the resulting box has the same...
\@rodriguez@bar \dimen@ \z@ \cr   % ... height as the first row
$\m@th #1#3$\cr
\@rodriguez@bar \z@ \dimen@ii \cr % ... depth as the last row
}%
}
\newcommand*\@rodriguez@bar[2]{%
\hidewidth \vrule \@width \dimen4 \@height #1\@depth #2\hidewidth
}

\makeatother

\begin{document}

In display:
$\barredsum_{i=1}^{N} x_{i} \neq \sum_{i=1}^{N} x_{i}$

In-line:
\begin{center}
$$\barredsum_{i=1}^{N} x_{i} \neq \sum_{i=1}^{N} x_{i}$$,
$$A_{\barredsum_{i=1}^{N} x_{i}} \neq A_{\sum_{i=1}^{N} x_{i}}$$,
$$A_{B^{\barredsum_{i=1}^{N} x_{i}}} \neq A_{B^{\sum_{i=1}^{N} x_{i}}}$$.
\end{center}

The barred product:
$\barredprod_{i=1}^{N} x_{i} \neq \prod_{i=1}^{N} x_{i}$
Etc.\ etc.

\end{document}


Admittedly, this solution lacks the round caps at the two ends of the vertical bar…

Edit: I meant to include an image showing the output, but I cllearly forgot to do so: I’m now correcting this.

• The round caps are precisely the reason… ;-) – egreg Aug 20 '19 at 10:00

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
\end{align}
\end{document}

• This meets the output some what ok, but this suggestion is not an advisable one...(sorry to say) – MadyYuvi Aug 20 '19 at 9:57
• @MadyYuvi Could you please explain why this solution is not advisable? – CarLaTeX Aug 21 '19 at 5:05
• He used the tag \hspace*{-1em} which was not the fixed one, if the OP increase the font size in future, then again he adjusted the horizontal space manually, all other answers have the feature of auto alignment, that's why I mentioned... – MadyYuvi Aug 21 '19 at 5:40

My knowledge about spacing is very limited, but here is one suggestion:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
$$\mathclap{\sum_{i=1}^N}{\Big\vert}\quad x_i$$
\end{document}