如何創造帶有垂直線的求和符號?

如何創造帶有垂直線的求和符號?

我正在嘗試創建這個符號:在此輸入影像描述

我嘗試過使用這個:

\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. 此解決方案使用\vphantominside \mathpalette,相當於巢\mathchoice狀節點,16 個結果組合中的每一個都包含一個picture環境。

特別是,這意味著\@barredsumbar每次調用該\barredsum命令都會執行該巨集 20 次。像我這樣見證過 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}

與垂直條相加

相關內容