如何才能使数学显示中的数学运算符号变得更大?

如何才能使数学显示中的数学运算符号变得更大?

我有一个$\boxplus$对参数的索引集合进行操作的运算符,类似于$\sum$$\prod$$\bigoplus$

以下使索引范围排版更好:

\usepackage{amsopn}
\DeclareMathOperator*{\op}{\boxplus}

但尺寸仍然是固定的,这看起来是错误的,特别是在 displaymath 中:

 $ \sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \op_{i=1}^3 x_i $
$$ \sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \op_{i=1}^3 x_i $$

如何才能使内联数学和显示数学使用适当的尺寸,就像和$\sum$$\prod$自动发生的情况一样$\bigoplus$

答案1

一个选项是使用\mathchoice

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

\newcommand{\op}{
  \mathop{
    \vphantom{\bigoplus} 
    \mathchoice
      {\vcenter{\hbox{\resizebox{\widthof{$\displaystyle\bigoplus$}}{!}{$\boxplus$}}}}
      {\vcenter{\hbox{\resizebox{\widthof{$\bigoplus$}}{!}{$\boxplus$}}}}
      {\vcenter{\hbox{\resizebox{\widthof{$\scriptstyle\oplus$}}{!}{$\boxplus$}}}}
      {\vcenter{\hbox{\resizebox{\widthof{$\scriptscriptstyle\oplus$}}{!}{$\boxplus$}}}}
  }\displaylimits 
}

\begin{document}

\begin{gather*}
\sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \op_{i=1}^3 x_i \\
{\textstyle\sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \op_{i=1}^3 x_i } \\
A_{\sum_{i=1}^3 x_i} \quad A_{\bigoplus_{i=1}^3 x_i} \quad A_{\op_{i=1}^3 x_i} \\
 B_{A_{\sum_{i=1}^3 x_i}} \quad B_{A_{\bigoplus_{i=1}^3 x_i}} \quad B_{A_{\op_{i=1}^3 x_i}} 
\end{gather*}

\end{document}

在此处输入图片描述

大部分宏与 等效\mathpalette,可避免代码重复。还有其他一些小修复。

\makeatletter
\newcommand*{\op}{%
  \DOTSB
  \mathop{\vphantom{\bigoplus}\mathpalette\matt@op\relax}%
  \slimits@
}
\newcommand\matt@op[2]{%
  \vcenter{\m@th\hbox{\resizebox{\widthof{$#1\bigoplus$}}{!}{$\boxplus$}}}%
}
\makeatother

答案2

对于简单的几何形状,picture模式是无价的:

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

\makeatletter
\newcommand*{\bigboxplus}{\DOTSB\mathop{\mathpalette\big@boxplus\relax}\slimits@}

\newcommand{\big@boxplus}[2]{%
  \vcenter{%
    \m@th\bigbox@thickness{#1}%
    \sbox\z@{$#1\bigoplus$}%
    \dimen@=\ht\z@ \advance\dimen@\dp\z@
    \hbox{%
      \setlength{\unitlength}{\dimen@}%
      \begin{picture}(1,1)
      \polyline(0.1,0.1)(0.9,0.1)(0.9,0.9)(0.1,0.9)(0.1,0.1)(0.5,0.1)
      \polyline(0.5,0.1)(0.5,0.9)
      \polyline(0.1,0.5)(0.9,0.5)
      \end{picture}%
    }%
  }%
}

\newcommand{\bigbox@thickness}[1]{%
  \ifx#1\displaystyle
    \linethickness{0.2ex}%
  \else
    \ifx#1\textstyle
      \linethickness{0.16ex}%
    \else
      \ifx#1\scriptstyle
        \linethickness{0.12ex}%
      \else
        \linethickness{0.1ex}%
      \fi
    \fi
  \fi
}
\makeatother

\begin{document}

\begin{gather*}
\sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \bigboxplus_{i=1}^3 x_i \\
{\textstyle\sum_{i=1}^3 x_i \quad \bigoplus_{i=1}^3 x_i \quad \bigboxplus_{i=1}^3 x_i } \\
A_{\sum_{i=1}^3 x_i} \quad A_{\bigoplus_{i=1}^3 x_i} \quad A_{\bigboxplus_{i=1}^3 x_i} \\
 B_{A_{\sum_{i=1}^3 x_i}} \quad B_{A_{\bigoplus_{i=1}^3 x_i}} \quad B_{A_{\bigboxplus_{i=1}^3 x_i}} 
\end{gather*}

\end{document}

在此处输入图片描述

相关内容