长串数字

长串数字

我有一个集合列表,其中一些集合有近 1000 个元素,而另一些集合有 14 个元素。目前我使用\\&来分隔行,但不知何故看起来不太合适。有些行似乎比另一行长。是否可以自动将它们分成几行并对齐,以使所有长度都相同。

这是我的代码:

\begin{align*}
R=&[0,1,2,3,5,6,7,8,9,11,13,15,17,19,21,22,23,24,25, 27, 28,29]\\
S=&[4, 5, 11, 16, 18, 19, 23, 24, 26, 31, 33, 37, 41, 44, 48, 49, 50, 53, 54, 60, 66, 67, 68, 74, 77, 78, 79,\\
& 80, 81, 82, 85, 87, 88, 91, 92, 93, 94, 95, 100, 102, 103, 104, 107, 109, 110, 111, 114, 115, 117, 119,\\
& 120, 122, 123, 124, 125, 133, 138, 139, 141, 142, 145, 146, 147, 151, 152, 155, 158, 161, 163, 164,\\
& 165, 169, 171, 172, 173, 174, 175, 178, 180, 181, 183, 184, 185, 187, 189, 195, 196, 197, 198, 200, 201,]
\end{align*}

如果您运行该命令,您将看到 79、119、164、201 是该行的末尾,但未对齐。在此处输入图片描述

答案1

为了自动换行,您必须指定线宽;在我建议的宏中,宽度是当前线宽的 80%,但可以使用可选参数进行调整,如线所示T

\documentclass{article}
\usepackage{amsmath}

\newcommand{\numberlist}[2][0.8\linewidth]{%
  [\parbox[t]{#1}{\printcommalist{#2}}%
}
\newcommand{\printcommalist}[1]{%
  \begingroup\lccode`~=`,\lowercase{\endgroup\def~}{\mathcomma\penalty0 }%
  \mathcode`,="8000
  \thinmuskip=6mu plus 6mu minus 2mu
  $#1]$
}
\mathchardef\mathcomma=\mathcode`,

\begin{document}

\begin{align*}
R&=[0,1,2,3,5,6,7,8,9,11,13,15,17,19,21,22,23,24,25, 27, 28,29]\\
S&=\numberlist{
  4, 5, 11, 16, 18, 19, 23, 24, 26, 31, 33, 37, 41, 44, 48, 49,
  50, 53, 54, 60, 66, 67, 68, 74, 77, 78, 79, 80, 81, 82, 85, 87,
  88, 91, 92, 93, 94, 95, 100, 102, 103, 104, 107, 109, 110, 111,
  114, 115, 117, 119, 120, 122, 123, 124, 125, 133, 138, 139, 141,
  142, 145, 146, 147, 151, 152, 155, 158, 161, 163, 164, 165, 169,
  171, 172, 173, 174, 175, 178, 180, 181, 183, 184, 185, 187, 189,
  195, 196, 197, 198, 200, 201
}\\
T&=\numberlist[.6\linewidth]{
  4, 5, 11, 16, 18, 19, 23, 24, 26, 31, 33, 37, 41, 44, 48, 49,
  50, 53, 54, 60, 66, 67, 68, 74, 77, 78, 79, 80, 81, 82, 85, 87,
  88, 91, 92, 93, 94, 95, 100, 102, 103, 104, 107, 109, 110, 111,
  114, 115, 117, 119, 120, 122, 123, 124, 125, 133, 138, 139, 141,
  142, 145, 146, 147, 151, 152, 155, 158, 161, 163, 164, 165, 169,
  171, 172, 173, 174, 175, 178, 180, 181, 183, 184, 185, 187, 189,
  195, 196, 197, 198, 200, 201
}
\end{align*}

\end{document}

在此处输入图片描述

如果你喜欢更随意的外观,带有参差不齐的线条,只需将线条

\thinmuskip=6mu plus 6mu minus 2mu

进入

\raggedright

这将给予

在此处输入图片描述

允许列表跨页的不同实现。

\documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum} % for mock text

\newenvironment{numberlists}[1][3\parindent]
 {\begin{list}{}{%
   \leftmargin=#1\relax
   \rightmargin=\leftmargin
   \itemsep=\jot
   \parsep=0pt
   \partopsep=0pt
   \labelsep=0pt}}
 {\end{list}}

\newcommand\numlist[2]{%
  \item[]\makebox[0pt][r]{$#1=\lbrack$}%
  \begingroup
  \begingroup\lccode`~=`,\lowercase{\endgroup\def~}{\mathcomma\penalty0 }%
  \mathcode`,="8000
  \thinmuskip=6mu plus 6mu minus 2mu
  $#2\rbrack$%
  \endgroup
}

\mathchardef\mathcomma=\mathcode`,

\begin{document}

\lipsum*[2-6]
\begin{numberlists}
\numlist{R}{0,1,2,3,5,6,7,8,9,11,13,15,17,19,21,22,23,24,25, 27, 28,29}

\numlist{S}{
  4, 5, 11, 16, 18, 19, 23, 24, 26, 31, 33, 37, 41, 44, 48, 49,
  50, 53, 54, 60, 66, 67, 68, 74, 77, 78, 79, 80, 81, 82, 85, 87,
  88, 91, 92, 93, 94, 95, 100, 102, 103, 104, 107, 109, 110, 111,
  114, 115, 117, 119, 120, 122, 123, 124, 125, 133, 138, 139, 141,
  142, 145, 146, 147, 151, 152, 155, 158, 161, 163, 164, 165, 169,
  171, 172, 173, 174, 175, 178, 180, 181, 183, 184, 185, 187, 189,
  195, 196, 197, 198, 200, 201
}
\end{numberlists}
\lipsum[3]

\end{document}

在此处输入图片描述

相关内容