如何減少 $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)來自 plain TeX,其中讀取

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

(看教材,p。 361);在這兩種情況下,單字「mod」之前的空格都是 1em 寬。第 4 頁給出的使用範例。 164 的教材以及練習 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,一個已經連結到的問題接受的答案對於這個問題)。可以看到,「不顯示」的情況是透過\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。我提出兩種方法:使用案例eqparbox`cases*中的環境來對齊模數條件:mathtools (simpler syntax), and with a standard,and

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

在此輸入影像描述

相關內容