如何减少 $n\equiv 1\pmod{4}$ 之间的空格

如何减少 $n\equiv 1\pmod{4}$ 之间的空格

我运行了以下代码,并在使用函数时得到了以下巨大的空间\pmod。这在论文中看起来很奇怪。有人能建议如何减少空间吗?

\begin{eqnarray*}
    MSC(C_n^2) &=& \begin{cases}
           1, & \text{if $n$ is odd and d is even ($n\equiv 1\pmod{4}$)},\\
           2, & \mbox{if n is even and d is even ($n\equiv 0\pmod {4}$)},\\
           3, & \mbox{if n is odd and d is odd ($n\equiv 3\pmod {4}$)},\\
           3, & \mbox{if n is even and d is odd ($n\equiv 2\pmod {4}$)}.
           \end{cases}
\end{eqnarray*}

在此处输入图片描述

答案1

下列的在全等式问题中写 mod 时无需前导空格,使用\Mod定义如下:

在此处输入图片描述

\documentclass{article}

\usepackage{amsmath}
\newcommand{\Mod}[1]{\ (\mathrm{mod}\ #1)}

\begin{document}

\begin{align*}
  MSC(C_n^2) &= 
    \begin{cases}
      1, & \text{if $n$ is odd and $d$ is even ($n \equiv 1 \Mod{4}$)},  \\
      2, & \text{if $n$ is even and $d$ is even ($n \equiv 0 \Mod{4}$)}, \\
      3, & \text{if $n$ is odd and $d$ is odd ($n \equiv 3 \Mod{4}$)},   \\
      3, & \text{if $n$ is even and $d$ is odd ($n \equiv 2 \Mod{4}$)}.
    \end{cases}
\end{align*}

\end{document}

答案2

从斜体字体来看,该显示位于定理语句内。

我会避免使用括号和重复的公共部分:

\documentclass{article}
\usepackage{amsmath}

\newtheorem{theorem}{Theorem}
\DeclareMathOperator{\MSC}{MSC}

\begin{document}

\begin{theorem}
Blah, blah
\begin{equation*}
\MSC(C_n^2)=
\begin{cases}
  1, & \text{if $n$ is odd and $d$ is even, i.e., $n\equiv 1$},\\
  2, & \text{if $n$ is even and $d$ is even, i.e., $n\equiv 0$},\\
  3, & \text{if $n$ is odd and $d$ is odd, i.e., $n\equiv 3$},\\
  3, & \text{if $n$ is even and $d$ is odd, i.e., $n\equiv 2$},
\end{cases}
\end{equation*}
where congruences are modulo~$4$.
\end{theorem}

\end{document}

一些说明:

  1. “MSC”应端正态度,以操作员身份对待;
  2. 即使在斜体字体的情况下,数学变量也应该在数学模式下输入;
  3. eqnarray在可用时不应使用amsmath(并且只要文档中包含严肃的数学运算就应加载它;
  4. 使用适当的环境,在这种情况下equation*是因为您没有对齐。

在此处输入图片描述

答案3

LaTeX 内核借用了\pmod

\def\pmod#1{%
  \allowbreak\mkern18mu({\operator@font mod}\,\,#1)}

(参见ltmath.dtx,代码行 39-40)来自纯 TeX,其中读取

\def\pmod#1{\allowbreak\mkern18mu({\rm mod}\,\,#1)}

(看TeXbook,第 361 页);在这两种情况下,“mod”一词前面的空格都是 1em 宽。第 164 页给出的使用示例TeXbook以及练习 18.4 的答案表明 Knuth 的意图是,在内联数学公式中也应该使用这种大小的空间。尽管如此,该amsmath包修改了上述定义,以便在公式“不显示”时使用更窄的空间:

\newcommand{\pod}[1]{\allowbreak
  \if@display\mkern18mu\else\mkern8mu\fi(#1)}
\renewcommand{\pmod}[1]{\pod{{\operator@font mod}\mkern6mu#1}}

(也可以看看这个答案在全等式问题中写 mod 时无需前导空格,一个已经链接自接受的答案(对这个问题的回答)可以看到,通过 switch来检测“未显示”的情况\if@display

思考这个问题时,我开始怀疑这是否是软件包中的一个错误,或者说是一个设计缺陷。也许一个更好的想法是让空间量随当前数学样式而变化,其方式类似于“大运算符”符号在显示和非显示数学之间改变其大小(以及某种程度上改变其形状)的方式\sum。此行为可以通过以下代码显示\int的命令补丁\pod(由软件包定义)轻松实现:amsmath

% 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} % Required for what follows; but...
\usepackage{mathtools} % ... "mathtools" automatically loads "amsmath".

\makeatletter

\renewcommand*\pod[1]{%
  \allowbreak
  \mathchoice
    {\mkern 18mu}%
    {\mkern  8mu}%
    {\mkern  8mu}%
    {\mkern  8mu}%
  (#1)%
}

\makeatother

\newtheorem{thm}{Theorem}



\begin{document}

In-line: \( 5\equiv 1 \pmod 4 \).  In display:
\[ 5\equiv 1 \pmod 4 \]
Non-display inside display:
\[
    f(x) =
        \begin{cases}
            4 & \mbox{if $x\equiv 0 \pmod 4$,} \\
            x\bmod 4 & \mbox{otherwise.}
        \end{cases}
\]
The same thing, but with \texttt{cases*} (requires \textsf{mathtools}):
\[
    f(x) =
        \begin{cases*}
            4 & if $x\equiv 0 \pmod 4$, \\
            x\bmod 4 & otherwise.
        \end{cases*}
\]

\begin{thm}
    All over again.
    In-line: \( 5\equiv 1 \pmod 4 \).  In display:
    \[ 5\equiv 1 \pmod 4 \]
    Non-display inside display:
    \[
        f(x) =
            \begin{cases}
                4 & \mbox{if $x\equiv 0 \pmod 4$,} \\
                x\bmod 4 & \mbox{otherwise.}
            \end{cases}
    \]
    With \texttt{cases*}:
    \[
        f(x) =
            \begin{cases*}
                4 & if $x\equiv 0 \pmod 4$, \\
                x\bmod 4 & otherwise.
            \end{cases*}
    \]
\end{thm}

Nonetheless, inside an alignment, say
\begin{align*}
    2 &\equiv 9 \pmod 7 \\
    4 &\equiv 1 \pmod 3 \mbox{,}
\end{align*}
the output agrees with that of a displayed equation:
\[
    5\equiv 1 \pmod 4 \mbox{.}
\]

\end{document}

这是上述代码产生的输出:

代码输出

这种修改可以成为一种优雅而一致的方式来实现问题所要求的。如果\mod也使用该命令,也应该对其进行类似的修改。当然,如果不破坏使用这些功能的所有现有文档,就无法在包的代码中引入这些更改masmath……


添加: 继续思考这个问题,我认为\pmod在上下标中使用命令甚至是有意义的(见下面的例子);在这种情况下,似乎左括号前的空间应该更细。

% 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} % Required for what follows; but...
\usepackage{mathtools} % ... "mathtools" automatically loads "amsmath".

\makeatletter

\renewcommand*\pod[1]{%
  \allowbreak
  \mathchoice
    {\mkern 18mu}%
    {\mkern  8mu}%
    {\mkern  6mu}% "6mu" matches the space *after* the word "mod"
    {\mkern  6mu}%
  (#1)%
}

\makeatother

\newtheorem{thm}{Theorem}



\begin{document}

In-line: \( 5\equiv 1 \pmod{4} \).  In display:
\[ 5\equiv 1 \pmod{4} \]
Non-display inside display:
\[
    f(x) =
        \begin{cases}
            4 & \mbox{if $x\equiv 0 \pmod{4}$,} \\
            x\bmod 4 & \mbox{otherwise.}
        \end{cases}
\]
The same thing, but with \texttt{cases*} (requires \textsf{mathtools}):
\[
    f(x) =
        \begin{cases*}
            4 & if $x\equiv 0 \pmod{4}$, \\
            x\bmod 4 & otherwise.
        \end{cases*}
\]

\begin{thm}
    All over again.
    In-line: \( 5\equiv 1 \pmod{4} \).  In display:
    \[ 5\equiv 1 \pmod{4} \]
    Non-display inside display:
    \[
        f(x) =
            \begin{cases}
                4 & \mbox{if $x\equiv 0 \pmod{4}$,} \\
                x\bmod 4 & \mbox{otherwise.}
            \end{cases}
    \]
    With \texttt{cases*}:
    \[
        f(x) =
            \begin{cases*}
                4 & if $x\equiv 0 \pmod{4}$, \\
                x\bmod 4 & otherwise.
            \end{cases*}
    \]
\end{thm}

Nonetheless, inside an alignment, say
\begin{align*}
    2 &\equiv 9 \pmod{7} \\
    4 &\equiv 1 \pmod{3} \mbox{,}
\end{align*}
the output agrees with that of a displayed equation:
\[
    5\equiv 1 \pmod{4} \mbox{.}
\]

In super\slash subscripts:
\[
    \int_{0}^{3\pi} \sin x\,dx
        = -\cos x \biggr|_{0}^{3\pi}
        = -\cos x \biggr|_{x\equiv 0 \pmod{2\pi}}^{x\equiv 3\pi \pmod{2\pi}}
        = -\cos x \biggr|_{0}^{\pi}
        = 1-(-1) = 2
\]

\end{document}

第二种情况的输出是

第二个代码示例的输出

答案4

我认为\pmod在括号内使用看起来不太好看,尤其是当外部(文本)括号是斜体时,所以我建议改用\bmod。我建议两种方法:使用cases*来自mathtools (simpler syntax), and with a standardcases ,andeqparbox` 的环境来对齐模数条件:

\documentclass{article}

\usepackage{mathtools}
\usepackage{eqparbox}

\begin{document}

\begin{align*}
  MSC(C_n^2) &=
    \begin{cases}
       1, &  \eqparbox{CN}{if $n$ is odd and $d$ is even} (n \equiv 1 \bmod{4}), \\
       2, &  \eqparbox{CN}{if $n$ is even and $d$ is even\enspace} (n \equiv 0 \bmod{4}), \\
       3, &  \eqparbox{CN}{ if $n$ is odd and $d$ is odd}  (n \equiv 3 \bmod{4}), \\
       3, & \eqparbox{CN}{ if $n$ is even and $d$ is odd } (n \equiv 2 \bmod{4}).
  \end{cases}
\end{align*}

\begin{align*}
  MSC(C_n^2) &=
    \begin{cases*}
      1, & if $n$ is odd and $d$ is even ($n \equiv 1 \bmod{4}$), \\
      2, & if $n$ is even and $d$ is even ($n \equiv 0 \bmod{4}$), \\
      3, & if $n$ is odd and $d$ is odd ($n \equiv 3 \bmod{4}$), \\
      3, & if $n$ is even and $d$ is odd ($n \equiv 2 \bmod{4}$).
    \end{cases*}
\end{align*}

\end{document} 

在此处输入图片描述

相关内容