将一组内容拆分为两行

将一组内容拆分为两行

我正在尝试将以下内容包含在我的文档中:

$$\mathcal{C} = \{84, 156, 204, 228, 276, 312, 348, 372, 408, 440, 444, 456, 468, 492, 555, 696, 708, 732, 744, 780, 804, 816, 828, 852, 876, 888, 912, 920, 936, 948, 952, 984, 996\}$$.

但是,它仍然在一行上。我该如何修复它,让它分成多行?如果可能的话,我希望括号能括住所有行。

答案1

您可以让 TeX 计算换行符。

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\usepackage{lipsum} % just for the example

\ExplSyntaxOn
\NewDocumentCommand{\longset}{mm}
 {
  \begin{gathered}
  \egreg_longset:nn { #1 } { #2 }
  \end{gathered}
 }

\box_new:N \l_egreg_longset_set_box
\seq_new:N \l_egreg_longset_elements_seq

\cs_new_protected:Nn \egreg_longset:nn
 {
  % measure the left hand side (with the open brace)
  \hbox_set:Nn \l_egreg_longset_set_box { $#1=\lbrace\,$ }
  % typeset the left hand side and the open brace
  #1 = \lbrace\,
  % add a minipage, the width is \displaywidth, minus the left hand side
  % minus 4em to have space for the equation number
  \begin{minipage}[t]
   {
    \dim_eval:n { \displaywidth - \box_wd:N \l_egreg_longset_set_box - 4em }
   }
  % add some stretching to \thinmuskip
  \muskip_set:Nn \thinmuskip { 1\thinmuskip plus 5mu }
  % split the input at commas
  \seq_set_from_clist:Nn \l_egreg_longset_elements_seq { #2 }
  % use the items, adding back the comma, followed by a penalty
  % so a line break can be taken
  $\seq_use:Nn \l_egreg_longset_elements_seq { , \penalty0~ }\,\rbrace$
  % the end
  \end{minipage}
 }
\ExplSyntaxOff

\begin{document}

\lipsum*[2]
\begin{equation*}
\longset{\mathcal{C}}{
  84, 156, 204, 228, 276, 312, 348, 372, 408, 440, 444, 456, 468, 492,
  555, 696, 708,732, 744, 780, 804, 816, 828, 852, 876, 888, 912, 920,
  936, 948, 952, 984, 996
}
\end{equation*}
\lipsum*[3]
\begin{equation}
\longset{\mathcal{C}}{
  84, 156, 204, 228, 276, 312, 348, 372, 408, 440, 444, 456, 468, 492,
  555, 696, 708,732, 744, 780, 804, 816, 828, 852, 876, 888, 912, 920,
  936, 948, 952, 984, 996
}
\end{equation}
\lipsum[4]

\end{document}

在此处输入图片描述

答案2

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
  \mathcal{C} = \{\,
  & 84, 156, 204, 228, 276, 312, 348, 372, 408, 440, 444, 456, 468, 492, \\
  & 555, 696, 708,732, 744, 780, 804, 816, 828, 852, 876, 888, 912, 920, \\
  & 936, 948, 952, 984, 996\,\}\enspace.
\end{align*}
\end{document}

相关内容