列表的自动格式化

列表的自动格式化

我需要将一长串列表放入 LaTeX 中,希望能够自动格式化。例如,我有以下列表:

\{\{7, 2, 6, 5\}, \{7, 2, 6, 6\}, \{7, 3, 1, 1\}, \{7, 3, 1, 3\},
\{7, 3, 1, 6\}, \{7, 3, 2, 2\}, \{7, 3, 2, 3\}, \{7, 3, 2, 4\}, \{7,
3, 3, 1\}, \{7, 3, 3, 2\}, \{7, 3, 3, 3\}, \{7, 3, 3, 4\}, \{7, 3,
3, 5\}, \{7, 3, 3, 6\}, \{7, 3, 4, 2\}, \{7, 3, 4, 3\}, \{7, 3, 4,
4\}, \{7, 3, 4, 5\}, \{7, 3, 5, 3\}, \{7, 3, 5, 4\}, \{7, 3, 5, 5\},
\{7, 3, 5, 6\}, \{7, 3, 6, 1\}, \{7, 3, 6, 3\}, \{7, 3, 6, 5\}, \{7,
3, 6, 6\}, \{7, 4, 1, 1\}, \{7, 4, 1, 2\}, \{7, 4, 1, 4\}, \{7, 4,
1, 6\}, \{7, 4, 2, 1\}, \{7, 4, 2, 2\}, \{7, 4, 2, 3\}, \{7, 4, 2,
4\}, \{7, 4, 3, 2\}, \{7, 4, 3, 3\}, \{7, 4, 3, 4\}, \{7, 4, 3, 5\},
\{7, 4, 4, 1\}, \{7, 4, 4, 2\}, \{7, 4, 4, 3\}, \{7, 4, 4, 4\}, \{7,
4, 4, 5\}, \{7, 4, 4, 6\}, \{7, 4, 5, 3\}, \{7, 4, 5, 4\}, \{7, 4,
5, 5\}, \{7, 4, 6, 1\}, \{7, 4, 6, 4\}, \{7, 4, 6, 6\}, \{7, 5, 1,
1\}, \{7, 5, 1, 2\}, \{7, 5, 1, 5\}, \{7, 5, 2, 1\}, \{7, 5, 2, 2\},
\{7, 5, 2, 5\}, \{7, 5, 2, 6\}, \{7, 5, 3, 3\}, \{7, 5, 3, 4\}, \{7,
5, 3, 5\}, \{7, 5, 3, 6\}, \{7, 5, 4, 3\}, \{7, 5, 4, 4\}, \{7, 5,
4, 5\}, \{7, 5, 5, 1\}, \{7, 5, 5, 2\}, \{7, 5, 5, 3\}, \{7, 5, 5,
4\}, \{7, 5, 5, 5\}, \{7, 5, 5, 6\}, \{7, 5, 6, 2\}, \{7, 5, 6, 3\},
\{7, 5, 6, 5\}, \{7, 5, 6, 6\}, \{7, 6, 1, 1\}, \{7, 6, 1, 3\}, \{7,
6, 1, 4\}, \{7, 6, 1, 6\}, \{7, 6, 2, 2\}, \{7, 6, 2, 5\}, \{7, 6,
2, 6\}, \{7, 6, 3, 1\}, \{7, 6, 3, 3\}, \{7, 6, 3, 5\}, \{7, 6, 3,
6\}, \{7, 6, 4, 1\}, \{7, 6, 4, 4\}, \{7, 6, 4, 6\}, \{7, 6, 5, 2\},
\{7, 6, 5, 3\}, \{7, 6, 5, 5\}, \{7, 6, 5, 6\}, \{7, 6, 6, 1\}, \{7,
6, 6, 2\}, \{7, 6, 6, 3\}, \{7, 6, 6, 4\},\{7, 6, 6, 5\}, \{7, 6,
6, 6\}\}

请注意,这只是整个列表的一小部分。我是否忽略了某个包?我似乎无法让该listings包工作,并且我宁愿不必为此使用multline或,align*因为我必须计算并输入\\每个换行符。有什么想法吗?

答案1

在此处输入图片描述

\documentclass{article}
\newcommand\z{,\linebreak[0]}
\begin{document}

\begin{raggedright}
$\{7, 2, 6, 5\}\z \{7, 2, 6, 6\}\z \{7, 3, 1, 1\}\z \{7, 3, 1, 3\}\z
\{7, 3, 1, 6\}\z \{7, 3, 2, 2\}\z \{7, 3, 2, 3\}\z \{7, 3, 2, 4\}\z
\{7, 3, 3, 1\}\z \{7, 3, 3, 2\}\z \{7, 3, 3, 3\}\z \{7, 3, 3, 4\}\z
\{7, 3, 3, 5\}\z \{7, 3, 3, 6\}\z \{7, 3, 4, 2\}\z \{7, 3, 4, 3\}\z
\{7, 3, 4, 4\}\z \{7, 3, 4, 5\}\z \{7, 3, 5, 3\}\z \{7, 3, 5, 4\}\z
\{7, 3, 5, 5\}\z \{7, 3, 5, 6\}\z \{7, 3, 6, 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1\}\z \{7, 6, 4, 4\}\z \{7, 6, 4, 6\}\z
\{7, 6, 5, 2\}\z \{7, 6, 5, 3\}\z \{7, 6, 5, 5\}\z \{7, 6, 5, 6\}\z
\{7, 6, 6, 1\}\z \{7, 6, 6, 2\}\z \{7, 6, 6, 3\}\z \{7, 6, 6, 4\}\z
\{7, 6, 6, 5\}\z \{7, 6, 6, 6\}\}$
\end{raggedright}

\end{document}

答案2

您可以简化输入语法并进行居中(但列表不能跨页拆分):

\documentclass{article}
\usepackage{xparse,lipsum,varwidth}

\ExplSyntaxOn
\NewDocumentCommand{\printbiglist}{m}
 {
  \[
  \begin{varwidth}{.8\textwidth}\raggedright 
  $\makebox[0pt][r]{$\lbrace$} % the opening brace hanging left
  \dan_print_biglist:n { #1 }
  \makebox[0pt][l]{$\rbrace$}$ % the closing brace hanging right
  \end{varwidth}
  \]
 }

\seq_new:N \l_dan_biglist_seq

\cs_new_protected:Npn \dan_print_biglist:n #1
 {
  \seq_set_split:Nnn \l_dan_biglist_seq { , } { #1 }
  \{ \seq_use:Nn \l_dan_biglist_seq { \},\linebreak[0]\{ } \}
 }

\ExplSyntaxOff

\begin{document}

\lipsum*[3]
\printbiglist{
  {7, 2, 6, 5}, {7, 2, 6, 6}, {7, 3, 1, 1}, {7, 3, 1, 3},
  {7, 3, 1, 6}, {7, 3, 2, 2}, {7, 3, 2, 3}, {7, 3, 2, 4},
  {7, 3, 3, 1}, {7, 3, 3, 2}, {7, 3, 3, 3}, {7, 3, 3, 4},
  {7, 3, 3, 5}, {7, 3, 3, 6}, {7, 3, 4, 2}, {7, 3, 4, 3},
  {7, 3, 4, 4}, {7, 3, 4, 5}, {7, 3, 5, 3}, {7, 3, 5, 4},
  {7, 3, 5, 5}, {7, 3, 5, 6}, {7, 3, 6, 1}, {7, 3, 6, 3},
  {7, 3, 6, 5}, {7, 3, 6, 6}, {7, 4, 1, 1}, {7, 4, 1, 2},
  {7, 4, 1, 4}, {7, 4, 1, 6}, {7, 4, 2, 1}, {7, 4, 2, 2},
  {7, 4, 2, 3}, {7, 4, 2, 4}, {7, 4, 3, 2}, {7, 4, 3, 3},
  {7, 4, 3, 4}, {7, 4, 3, 5}, {7, 4, 4, 1}, {7, 4, 4, 2},
  {7, 4, 4, 3}, {7, 4, 4, 4}, {7, 4, 4, 5}, {7, 4, 4, 6},
  {7, 4, 5, 3}, {7, 4, 5, 4}, {7, 4, 5, 5}, {7, 4, 6, 1},
  {7, 4, 6, 4}, {7, 4, 6, 6}, {7, 5, 1, 1}, {7, 5, 1, 2},
  {7, 5, 1, 5}, {7, 5, 2, 1}, {7, 5, 2, 2}, {7, 5, 2, 5},
  {7, 5, 2, 6}, {7, 5, 3, 3}, {7, 5, 3, 4}, {7, 5, 3, 5},
  {7, 5, 3, 6}, {7, 5, 4, 3}, {7, 5, 4, 4}, {7, 5, 4, 5},
  {7, 5, 5, 1}, {7, 5, 5, 2}, {7, 5, 5, 3}, {7, 5, 5, 4},
  {7, 5, 5, 5}, {7, 5, 5, 6}, {7, 5, 6, 2}, {7, 5, 6, 3},
  {7, 5, 6, 5}, {7, 5, 6, 6}, {7, 6, 1, 1}, {7, 6, 1, 3},
  {7, 6, 1, 4}, {7, 6, 1, 6}, {7, 6, 2, 2}, {7, 6, 2, 5},
  {7, 6, 2, 6}, {7, 6, 3, 1}, {7, 6, 3, 3}, {7, 6, 3, 5},
  {7, 6, 3, 6}, {7, 6, 4, 1}, {7, 6, 4, 4}, {7, 6, 4, 6},
  {7, 6, 5, 2}, {7, 6, 5, 3}, {7, 6, 5, 5}, {7, 6, 5, 6},
  {7, 6, 6, 1}, {7, 6, 6, 2}, {7, 6, 6, 3}, {7, 6, 6, 4},
  {7, 6, 6, 5}, {7, 6, 6, 6}
}
\lipsum[3]

\end{document}

在此处输入图片描述

如果你不关心居中,而是需要将大列表拆分到多个页面,请将主命令的定义更改为

\NewDocumentCommand{\printbiglist}{m}
 {
  \begin{quote}\raggedright 
  $\makebox[0pt][r]{$\lbrace$} % the opening brace hanging left
  \dan_print_biglist:n { #1 }
  \makebox[0pt][l]{$\rbrace$}$ % the closing brace hanging right
  \end{quote}
 }

相关内容