编辑

编辑

以下定义来自如何继续一段文本以使其与内联多行框的最后一行对齐?,允许将数学集合构建器表达式拆分为两行:

\newcommand\setst[2]{\{#1 : 
   \begin{array}[t]{@{}l@{}}#2 \}\end{array}}

我想:

  1. \{分别将和更改\}\left\{\right\}。以下尝试会产生缺少“\right. ”的错误;
  2. 不要让显示数学中通常较高的符号(例如积分符号)被环境挤压array

    我的语法有什么问题?

    \新命令\设置2{\left{#1 :\right. % \begin{array}[t]{@{}l@{}}\left.#2 \right}\end{array}}

以及如何解决被挤压的正常高度符号保留其正常的显示数学高度的问题?(参见下面的第二个源文件。)

示例来源(根据上面引用的链接修改):

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

\newcommand\setst[2]{\{#1 : 
  \begin{array}[t]{@{}l@{}}#2 \}\end{array}}

% my attempted mod
\newcommand\Setst[2]{\left\{#1 : \right. %
  \begin{array}[t]{@{}l@{}}\left.#2 \right\}\end{array}}

\begin{document}

Braces OK:
\[
\setst{x}{ x \in S_1 \land {} \\
          (x \in S_2 \lor x \in S_3) }
\]

Error:
\[
\Setst{x}{ x \in S_1 \land {} \\
          (x \in S_2 \lor x \in S_3) }
\]

\end{document}

以下是使用原始命令的“OK”版本的打印输出\setst

分割线集合生成器

目的是用相应的大括号替换输出中的 { 和 } — 当然,假设其中的数学表达式会导致这些括号扩展。但每个括号都应该不是扩展以包含打印输出的两行!

这是一个更现实的例子,确实需要更大的括号:

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

\newcommand\setst[2]{\{#1 : 
  \begin{array}[t]{@{}l@{}}#2 \}\end{array}}

% my attempted mod
\newcommand\Setst[2]{\left\{#1 : \right. %
  \begin{array}[t]{@{}l@{}}\left.#2 \right\}\end{array}}

\begin{document}

Works, but integral sign and absolute value get squashed down smaller than they ought to appear in display math:
\[
\setst{f}{f(t) > 0 \text{ for all $t$ with } 0 < t < 1\\
    \text{and }\left|\int_{0}^{1}e^{-\frac{1}{2} t^{2}}f(t) dt\right| \leq 1 }
\]

\end{document}

其输出结果如下,其中有两个括号:

分割线集合生成器 #2

答案1

我建议采用一种非全自动方法来调整外花括号的大小。在下面的代码中,外花括号的默认大小为\big,但可以通过指定可选的大小相关参数来更改,该参数可以采用值BiggbiggBig当然还有big)。我赞成最小尺寸为big(而不是正常尺寸),因为在我看来,花括号只需要“看起来”更突出一点。

在下面的屏幕截图中,第一个示例中的花括号的大小为\big(默认);\bigg在第二个示例中,它们的大小为 ,其中\displaystyle对第二行有效。

在此处输入图片描述

\documentclass{article}
\usepackage{mathtools} % for '\DeclarePairedDelimiter' macro
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert} % "absolute value" macro

\newcommand\Setst[3][big]{\csname #1l\endcsname\{ #2 : 
  \begin{array}[t]{@{}l@{}}#3\csname #1r\endcsname \}\end{array}}

\begin{document}
\[
\Setst{f}{\text{$f(t)>0$ for all $t$ with $0<t<1$}\\
          \text{and }\abs[\big]{\int_0^1 e^{-\frac{1}{2}t^2}\!f(t)\,dt}\leq1}
\]

\[ % use \displaystyle directive in second row; hence, use "bigg" curly braces
\Setst[bigg]{f}{\text{$f(t)>0$ for all $t$ with $0<t<1$}\\
  \displaystyle \text{and }\abs[\bigg]{\int_0^1 e^{-\frac{1}{2}t^2}\!f(t)\,dt}\leq1}
\] 
\end{document}

答案2

我将以略微不同的方式设置组件,以允许\left-\right用于跨越整个构造:

在此处输入图片描述

\documentclass{article}

\usepackage{amsmath,amssymb}

\newcommand\setst[2]{\{#1 : 
  \begin{array}[t]{@{}l@{}}#2 \}\end{array}}

% my attempted mod
\newcommand\Setst[2]{%
  \expandafter\setsttopandbottom#2\relax
  \begin{array}{@{}l @{\ } l@{}}
    \left\{#1 :\vphantom{\setsttop}\vphantom{\setstbottom}\right.\kern-\nulldelimiterspace & 
    \begin{array}[t]{@{}l@{}}
      \setsttop \\ \kern-\nulldelimiterspace\left.\setstbottom\vphantom{\setsttop}\right\}
    \end{array}
  \end{array}
  }

\def\setsttopandbottom#1\\#2\relax{\def\setsttop{#1}\def\setstbottom{#2}}

\begin{document}

OK:
\[
  \setst{f}{f(t) > 0 \text{ for all $t$ with } 0 < t < 1 \\
      \text{and }\left|\int_{0}^{1}e^{-\frac{1}{2} t^{2}}f(t) dt\right| \leq 1 }
\]

Modified:
\[
  \Setst{f}{f(t) > 0 \text{ for all $t$ with } 0 < t < 1\\
      \text{and }\left|\int_{0}^{1}e^{-\frac{1}{2} t^{2}}f(t) dt\right| \leq 1 }
\]

\end{document}

具体来说,第二个参数中的构造的顶部和底部被提取并用于第一行(用于开头\{)以及最后一行(用于结尾\})的测量。

上述解决方案假设您将总是在构造中使用\\,因此有两行。对于单行应用程序,必须构建单独的宏。


使用

\usepackage{array}

\newcommand\Setst[2]{%
  \expandafter\setsttopandbottom#2\relax
  \begin{array}{@{}>{\displaystyle}l @{\ } l@{}}
    \left\{#1 :\vphantom{\setsttop}\vphantom{\setstbottom}\right.\kern-\nulldelimiterspace & 
    \begin{array}[t]{@{}>{\displaystyle}l@{}}
      \setsttop \\ \kern-\nulldelimiterspace\left.\setstbottom\vphantom{\setsttop}\right\}
    \end{array}
  \end{array}
  }

array您始终可以确保使用 来设置构造内的单元格\displaystyle

答案3

这个答案只是一个草稿,旨在解释我发布时的想法我的评论

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

\makeatletter

\newcommand*{\SetSt}[2]{%
    \setbox\z@ \hbox{%
        % Inside this box, the "\\" command is `turned off'. 
        % BEWARE: WE ASSUME THAT "&" IS **NOT** USED INSIDE #2!
        \let\\\relax
        $#2$%
    }%
    \dimen@   \ht\z@
    \dimen@ii \dp\z@
    % Now typesetting begins:
    \left\{\,#1%
    % select one of the two following alternatives:
    % {}:{}% colon as separator
    \,\middle|\,% vertical bar as separator
    \vrule \@height\dimen@ \@depth\dimen@ii \@width\z@
    \right.\kern-\nulldelimiterspace
    \begin{array}[t]{@{}l@{}}%
        #2%
        \left.\kern-\nulldelimiterspace
        \vrule \@height\dimen@ \@depth\dimen@ii \@width\z@
        \right\}%
    \end{array}%
}

\makeatother



\begin{document}

With tall symbols:
\[
    \SetSt{f}{f(t) > 0 \text{ for all $t$ with } 0 < t < 1\\
        \text{and }\left|\int_{0}^{1}e^{-\frac{1}{2} t^{2}}f(t) dt\right| \leq 1 }
\]

WIthout tall symbols:
\[ \SetSt{x}{x\in A \land x\in B\\x\in C \land x\in D\\x\in E \land x\in F} \]
As you can see, no restriction is imposed on the number of lines.  Even a 
single line is OK\@:
\[ \SetSt{x}{\int_{0}^{x} f(t)\,dt > 0} \]

Another example with two lines:
\[
    \SetSt{x}{\int_{0}^{x} f(t)\,dt > 0\\\int_{0}^{x} g(t)\,dt > 0}
\]

\end{document}

至少可以从两个方面加以完善:

  • \\ 命令不应该简单地重新定义为\relax,它应该吞噬一个星号和一个可选参数(如果存在);

  • \SetSt命令应该考虑当前的数学风格;这可以通过常规应用轻松实现\mathpalette

很抱歉,但是现在我太累了,无法进行这些改进……

编辑

我现在可以发布修改后的代码版本:

% 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}
\usepackage{array}

\makeatletter

\newcommand*\SetSt[2]{\mathpalette{\@SetSt{#1}}{#2}}
\newcommand*\@SetSt[3]{%
    % #1 := 1st argument of "\SetSt"
    % #2 := style selector (e.g., "\displaystyle")
    % #3 := 2nd argument of "\SetSt"
    \setbox\z@ \hbox{%
        % Inside this box, the "\\" command is `turned off'. 
        % BEWARE: WE ASSUME THAT "&" IS **NOT** USED INSIDE #3!
        \let\\\@Murray@NoopCR
        $#2#3$%
    }%
    \dimen@   \ht\z@
    \dimen@ii \dp\z@
    % Now typesetting begins:
    \left\{\@nonscript@thinspace #2% style selector
    % The following group protects the value of "\dimen@" and "\dimen@ii":
    \begingroup #1\endgroup
    % select one of the two following alternatives:
    % {}:{}% colon as separator
    \@nonscript@thinspace\middle|\@nonscript@thinspace % vertical bar as separator
    \@Murray@mathstrut
    \right.\kern-\nulldelimiterspace
    % The group around the cells allows this macro to be nested;
    % it is important only for the last row, but we cannot avoid specifying it 
    % for every entry.
    \begin{array}[t]{@{}>{#2\begingroup}l<{\endgroup}@{}}%
        #3\endgroup % end the group to restore the values of "\dimen@" and 
                    % "dimen@ii"
        \left.\kern-\nulldelimiterspace
        \@Murray@mathstrut
        \right\}%
        \begingroup % to balance the "\endgroup" at the end of the entry
    \end{array}%
}
\newcommand*\@Murray@NoopCR{\@ifstar\x@Murray@NoopCR\x@Murray@NoopCR}
\newcommand*\x@Murray@NoopCR{\@ifnextchar[\y@Murray@NoopCR {}}
\@ifdefinable\y@Murray@NoopCR{\def\y@Murray@NoopCR[#1]{}}
\newcommand*\@nonscript@thinspace{\nonscript\mskip\thinmuskip}
\newcommand*\@Murray@mathstrut{%
    \vrule \@height\dimen@ \@depth\dimen@ii \@width\z@
}

\makeatother



\begin{document}

With tall symbols:
\[
    \SetSt{f}{f(t) > 0 \text{ for all $t$ with } 0 < t < 1\\[\medskipamount]
        \text{and }\left|\int_{0}^{1}e^{-\frac{1}{2} t^{2}}f(t) dt\right| \leq 1 }
\]

WIthout tall symbols:
\[ \SetSt{x}{x\in A \land x\in B\\x\in C \land x\in D\\x\in E \land x\in F} \]
As you can see, no restriction is imposed on the number of lines.  Even a 
single line is OK\@:
\[ \SetSt{x}{\int_{0}^{x} f(t)\,dt > 0} \]

Another example with two lines:
\[
    \SetSt{x}{\int_{0}^{x} f(t)\,dt > 0
    \\*[\bigskipamount]% the star serves no purpose, we just want to check that 
                       % it is handled correctly
    \int_{0}^{x} g(t)\,dt > 0}
\]

An example of nesting:
\[
    \SetSt{x}{x\in A\\x\in B\\x\in\SetSt{y}{y<-1\\y>1}}
\]
This last example clearly shows the limits of the algorithm.

\end{document}

它产生的输出如下:

修改后的代码输出

答案4

我建议用另一种方式来表示这个集合构造器符号,它有一个简单的解决方案,基于delarraystackengine。此外,我定义了一个\abs命令,\DeclarePairedDelimiterX来自mathtools,以及一个具有积分中正确间距的微分符号:

\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb, delarray}
\usepackage[usestackEOL]{stackengine}

\DeclarePairedDelimiterX{\abs}[1]{\lvert}{\rvert}{\ifblank{#1}{\:\cdot\:}{#1}}%%

\newcommand\mySetst[2]{ \begin{array}\{{@{}>{\everymath{\displaystyle}}c@{\::\:}>{\everymath{\displaystyle}}l@{}}\}
#1 & \stackMath\Shortunderstack[l]{#2}
 \end{array}}

\newcommand\dd[1]{\,\mathrm{d}\mkern 1mu#1} %% differential symbol for integrals

\begin{document}

 \[ \mySetst{f}{f(t)>0 \text{ for all $t$ with } 0<t<1\\\text{and }\abs*{int_{0}^{1}e^{-\frac{1}{2} t^{2}}f(t)\dd t} \leq 1} \]%
\
\end{document} 

在此处输入图片描述

相关内容