3

I have a list of sets and some of the sets have almost 1000 elements and some have 14 elements. At the moment I use \\ and & to separate the lines but somehow it doesn't look proper. Some lines appears to be longer than the other. Is it possible to like separate them in lines automatically and justify them so that all the length are the same.

Here is my code:

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

If you run the command you will see that 79, 119, 164, 201 are the end of the line but are not alligned.enter image description here

4

In order to automatically wrap you have to specify a line width; in the macro I propose, the width is 80% of the current line width, but can be adjusted with the optional argument, as shown in the T line.

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

enter image description here

If you prefer a more informal look, with ragged lines, just change the line

\thinmuskip=6mu plus 6mu minus 2mu

into

\raggedright

that would give

enter image description here

A different implementation that allows the lists to break across pages.

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

enter image description here

| improve this answer | |
  • Thank you so much for this. It really helped a lot. But then I wonder why it does not break into pages. Because supposedly the list of sets takes up to 4 pages. But now everything is compressed into one page passing through the page number till the bottom of the page. – shahrina ismail Sep 23 '15 at 11:03
  • @Sharina Breaking across pages is quite a different thing. I added a possible solution. – egreg Sep 23 '15 at 12:06
  • Thank you so much @egreg ! Thi has been of a great help. Just a quick question. Which command should I change if I require more elements per row. For example all the elements in R goes in a row instead of 2. – shahrina ismail Sep 23 '15 at 12:54
  • @Sharina You can call \begin{numberlists}[1cm] to make the margins equal to 1cm (the label sticks in the left margin). – egreg Sep 23 '15 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.