如何创建带有竖线的求和符号?

如何创建带有竖线的求和符号?

我正在尝试创建这个符号:在此处输入图片描述

我曾尝试使用这个:

\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}

但它没有以正确的方式实现,而且我也不确定如何使用分隔符。谢谢。

答案1

\ooalign这是和模式的混合picture

\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}

在此处输入图片描述

可能的改进,其中过冲是可变的并且符号具有与以下相同的垂直范围\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}

在此处输入图片描述

答案2

尝试改进 egreg 的一个答案是一项既令人愉快又有教育意义的练习,而且,它还能给你吹牛的权利。(;-) 在这种情况下,我认为接受的解决方案在效率方面不是最优的,原因如下:

  1. 在绘画时,例如,女巫需要 picture环境的充分灵活性,这种灵活性并不是需要画一条简单的线。

  2. 该解决方案使用\vphantom内部\mathpalette,相当于嵌套\mathchoice节点,其中产生的十六种组合中的每一个都包含一个picture环境。

具体来说,这意味着\@barredsumbar每次调用命令时,宏都会执行 20 次\barredsum。像我这样见证过 LaTeX 编译一篇论文需要半个多小时的英雄时代的人对这个说法特别敏感。

以下代码\@rodriguez@overprint@bar在每次调用 时仅执行四次宏\barredsum,并且仅依赖 TeX 的原始规则命令来绘制线条。作为额外的好处,它还定义了命令\barredprod,产生了 的禁止版本\prod:这显示了如何推广构造。

% 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} \),
    \quad
    \( A_{\barredsum_{i=1}^{N} x_{i}} \neq A_{\sum_{i=1}^{N} x_{i}} \),
    \quad
    \( 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}

不可否认的是,这个解决方案缺少垂直杆两端的圆形帽……

编辑: 我本来想包含一张显示输出的图像,但我显然忘了这样做:我现在正在纠正它。

代码输出

答案3

输出

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
    \sum_{i=1}^N {\Big\vert\quad x_i}\\
    \sum_{i=1}^N {\hspace{-1em}\Big\vert\quad x_i}\\
    \sum_{i=1}^N {\hspace{-1em}\Big\vert\hspace{1em}\quad x_i}
\end{align}
\end{document}

答案4

我对间距的了解非常有限,但这里有一个建议:

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

带竖线的和

相关内容