%TUGBoat article A Multienumerate Package \documentclass{article} \usepackage{multicol,multienum} \pagestyle{headings} \begin{document} \title{A Multienumerate Package} \author{Dennis Kletzing\\Stetson University} \date{\today} \maketitle \begin{abstract} {\it The {\tt multienum.sty} package allows the user to produce an enumerated array of multiple columns, each vertically aligned on the counter. An optional argument provides for consecutive numbering of the array items, or an even-only or odd-only numbering scheme.} \end{abstract} Typesetting the solutions manual for a text frequently involves creating an enumerated list involving many short answers. Typically these are set with several items per line, with no attempt made to vertically align the exercise numbers. The {\tt multienum.sty} package provides an environment, {\tt multienumerate}, that produces an enumerated array in which columns are vertically aligned on the counter. If the user wishes, the enumeration counter can be changed to give a list of even-only numbers or odd-only numbers. \begin{table}[b] \caption{An enumerate array of solutions} \parbox[t]{.99\hsize}{% \hrule\hrule \begin{multienumerate} \mitemxxxx{Not}{Linear}{Not}{Quadratic} \mitemxxxo{Not}{Linear}{No; if $x=3$, then $y=-2$.} \mitemxx{$(x_1,x_2)=(2+\frac{1}{3}t,t)$ or $(s,3s-6)$}{$(x_1,x_2,x_3)=(2+\frac{5}{2}s-3t,s,t)$} \mitemx{$(x_1,x_2,x_3,x_4)= (\frac{1}{4}+\frac{5}{4}s+\frac{3}{4}t-u,s,t,u)$ or $(s,t,u,\frac{1}{4}-s+\frac{5}{4}t+\frac{3}{4}u)$} \mitemxxxx{$(2,-1,3)$}{None}{$(2,1,0,1)$}{$(0,0,0,0)$} \end{multienumerate}}\hrule \end{table} \section*{What the package does} Table 1 shows a typical enumerated array. The fourth entry in the second row is left blank since the next item is too long to fit in space. The third row has only two entries. To get the vertical alignment of the counter in column 3, we set row three as four entries, but left entry 2 and entry 4 blank thus giving more space for the first and third entries. To produce the enumerated array shown above, we typed the following: \begin{verbatim} \begin{multienumerate} \mitemxxxx{Not}{Linear}{Not}{Quadratic} \mitemxxxo{Not}{Linear}{Not} \mitemxx{$(x_1,x_2)=(2+\frac{1}{3}t,t)$ or $(s,3s-6)$}{$(x_1,x_2,x_3)=(2+\frac{5}{2}s-3t,s,t)$} \mitemx{$(x_1,x_2,x_3,x_4)= (\frac{1}{4}+\frac{5}{4}s+\frac{3}{4}t-u,s,t,u)$ or $(s,t,u,\frac{1}{4}-s+\frac{5}{4}t+\frac{3}{4}u)$} \mitemxxxx{$(2,-1,3)$}{None}{$(2,1,0,1)$}{$(0,0,0,0)$} \end{multienumerate} \end{verbatim} The environment {\tt multienumerate} has an optional argument for enumerating even-only or odd-only arrays.\footnote{The optional arguments works only in \LaTeX2e.} \begin{itemize} \item \verb|\begin{multienumerate} ... \end{multienumerate}| \item[] produces a consecutively enumerated array \item \verb|\begin{multienumerate}[evenlist] ...\end{multienumerate}| \item[] produces an enumerated array using only even numbers \item \verb|\begin{multienumerate}[oddlist] ...\end{multienumerate}| \item[] produces an enumerated array using only odd numbers \end{itemize} \section*{Using the package} Each row of the enumerated array is set using one of the nine commands: \begin{small} \renewcommand{\arraystretch}{1.2}%1.4 \begin{tabular}{@{}lp{3in}} \verb|\mitemx{}|&A single item in the row.\\ \verb|\mitemxx{}{}|&Two items in the row.\\ \verb|\mitemxxx{}{}{}|&Three items in the row.\\ \verb|\mitemxox{}{}|&Three items in the row with the center item space left blank so the first item can extend into its space.\\ \verb|\mitemxxo{}{}|&Three items in the row with the last item left blank so the second item can extend into its space.\\ \verb|\mitemxxxx{}{}{}{}|&Four items in the row.\\ \verb|\mitemxoxx{}{}{}|& Four items in the row with the second space left blank so the first item can extend into its space.\\ \verb|\mitemxxox{}{}{}|&Four items in the row with the third space left blank so the second item can extend into its space.\\ \verb|\mitemxxxo{}{}{}|&Four items in the row with the last space left blank so the third item can extend into its space. \end{tabular} \end{small} For example, \verb|\mitemxxx{a}{b}{c}| sets three items, a, b, c equally spaced across the row; \verb|\mitemxox{a}{c}| sets the two items, a and c, across the row {\em as if\/} there were three items, leaving the second entry blank so that the first entry can extend into its space; and \verb|\mitemxxo{a}{b}| sets the two items, a and b, {\em as if\/} there were three items, but leaves the space for the third item blank, allowing the second entry to extend into its space. A convenient way to use the multienumerate package is with a two column layout using multicols. Page 7 illustrates a typical page from a solutions manual set in two columns format using multicols and multienumerate. A disadvantage of the package is that the user must choose how to typeset each line in the array rather than letting \TeX\ decide how to do it. This creates a lot of overhead in the macro since separate commands are needed for each possibility. It is not difficult to write a macro that will let \TeX\ decide how many items to set on each line. This approach, while the most efficient, does not always give the visual appearance that the user may want. \section{How the package works} We illustrate how the package typesets a line containing two items. The other situations are similar. \noindent \setlength{\unitlength}{1.3pt} \begin{picture}(240,50)(0,0) \put(0,0){\framebox(35,10)[b]{\hfill 1.}} \put(40,0){\framebox(30,10)[b]{}} \put(75,0){\framebox(50,10)[bl]{stuff}} \put(0,30){\makebox(35,10)[b]{\small \texttt{$\backslash$labelwidth}}} \put(40,30){\makebox(30,10)[b]{\small \texttt{$\backslash$labelsep}}} \put(75,30){\makebox(50,10)[b]{\small \texttt{$.5\backslash$remainxx}}} \put(17.5,20){\vector(-1,0){17.5}} \put(17.5,20){\vector(1,0){17.5}} \put(55,20){\vector(-1,0){15}} \put(55,20){\vector(1,0){15}} \put(100,20){\vector(-1,0){25}} \put(100,20){\vector(1,0){25}} \put(147.5,20){\vector(-1,0){17.5}} \put(147.5,20){\vector(1,0){17.5}} \put(185,20){\vector(-1,0){15}} \put(185,20){\vector(1,0){15}} \put(230,20){\vector(-1,0){25}} \put(230,20){\vector(1,0){25}} \put(130,0){\framebox(35,10)[b]{\hfill 2.}} \put(170,0){\framebox(30,10)[b]{}} \put(205,0){\framebox(50,10)[bl]{stuff}} \put(130,30){\makebox(35,10)[b]{\small \texttt{$\backslash$labelwidth}}} \put(170,30){\makebox(30,10)[b]{\small \texttt{$\backslash$labelsep}}} \put(205,30){\makebox(50,10)[b]{\small \texttt{$.5\backslash$remainxx}}} \end{picture} \bigskip The total width of the line is then set equal to \verb|\hsize|: \[\underbrace{2\texttt{$\backslash$labelwidth}+ 2\texttt{$\backslash$labelsep}}_{\texttt{$\backslash$usedxx}}+ \texttt{$\backslash$remainxx}=\texttt{$\backslash$hsize}\] \[\texttt{$\backslash$remainxx}= \texttt{$\backslash$hsize}- \texttt{$\backslash$usedxx}\] \bigskip In this way the macro determines the width of each box when two items are typeset on the line. \section{The macro} Here is the package \texttt{multienum.sty}. \begin{verbatim} \setlength{\hsize}{\textwidth} %First define new lengths \newlength{\usedx} \newlength{\remainx} \newlength{\usedxx} \newlength{\remainxx} \newlength{\usedxxx} \newlength{\remainxxx} \newlength{\usedxxxx} \newlength{\remainxxxx} \newlength{\remainxox} \newlength{\remainxoxx} %Define new item control sequences \newcommand{\itemx}[1]{\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep% \parbox[t]{\remainx}{\raggedright #1}\smallskip} \newcommand{\itemxx}[2]{\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{.5\remainxx}{\raggedright #1}\hfill\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{0.5\remainxx}{\raggedright #2}\smallskip} \newcommand{\itemxxx}[3]{\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep% \parbox[t]{.3333\remainxxx}{\raggedright #1}\hfill\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep% \parbox[t]{0.3333\remainxxx}{\raggedright #2}\hfill% \parbox[t]{\labelwidth}{\hfill\labelenumi}\hskip\labelsep% \parbox[t]{0.3333\remainxxx}{\raggedright #3}\smallskip} \newcommand{\itemxxxx}[4]{\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{.25\remainxxxx}{\raggedright #1}\hfill\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{0.25\remainxxxx}{\raggedright #2}\hfill% \parbox[t]{\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{0.25\remainxxxx}{\raggedright #3}\hfill% \parbox[t]{\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{0.25\remainxxxx}{\raggedright #4}\smallskip} \newcommand{\itemxox}[2]{\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{\remainxox}{\raggedright #1}\hfill% \parbox[t]{\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{0.3333\remainxxx}{\raggedright #2}\smallskip} \newcommand{\itemxxo}[2]{\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{0.3333\remainxxx}{\raggedright #1}\hfill% \parbox[t]{\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{\remainxox}{\raggedright #2}\smallskip} \newcommand{\itemxoxx}[3]{\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{\remainxoxx}{\raggedright #1}\hfill% \parbox[t]{\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{0.25\remainxxxx}{\raggedright #2}\hfill% \parbox[t]{\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{0.25\remainxxxx}{\raggedright #3}\smallskip} \newcommand{\itemxxox}[3]{\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{.25\remainxxxx}{\raggedright #1}\hfill% \parbox[t]{\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{\remainxoxx}{\raggedright #2}\hfill% \parbox[t]{\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{0.25\remainxxxx}{\raggedright #3}\smallskip} \newcommand{\itemxxxo}[3]{\parbox[t]% {\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{.25\remainxxxx}{\raggedright #1}\hfill% \parbox[t]{\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{.25\remainxxxx}{\raggedright #2}\hfill% \parbox[t]{\labelwidth}{\hfill\labelenumi}\hskip\labelsep \parbox[t]{\remainxoxx}{\raggedright #3}\smallskip} \newcommand{\mitemx}[1]{\item[] \itemx{#1}} \newcommand{\mitemxx}[2]{\item[] \itemxx{#1}{#2}} \newcommand{\mitemxxx}[3]{\item[] \itemxxx{#1}{#2}{#3}} \newcommand{\mitemxox}[2]{\item[] \itemxox{#1}{#2}} \newcommand{\mitemxxo}[2]{\item[] \itemxxo{#1}{#2}} \newcommand{\mitemxxxx}[4]{\item[] \itemxxxx{#1}{#2}{#3}{#4}} \newcommand{\mitemxoxx}[3]{\item[] \itemxoxx{#1}{#2}{#3}} \newcommand{\mitemxxox}[3]{\item[] \itemxxox{#1}{#2}{#3}} \newcommand{\mitemxxxo}[3]{\item[] \itemxxxo{#1}{#2}{#3}} \newcommand{\mitemxxoo}[2]{\item[] \itemxxoo{#1}{#2}} %Create counter options \newcommand{\oddlist}{\setcounter{enumi}{-1} \renewcommand{\labelenumi} {\ifodd\value{enumi}\addtocounter{enumi}{2}% \arabic{enumi}.\else \addtocounter{enumi}{1}\arabic{enumi}.% \addtocounter{enumi}{-2}\fi}} \newcommand{\evenlist}{\setcounter{enumi}{0} \renewcommand{\labelenumi} {\ifodd\value{enumi}\addtocounter{enumi}{1}\arabic{enumi}.% \addtocounter{enumi}{-2}\else \addtocounter{enumi}{2}\arabic{enumi}.\fi}} \newcommand{\regularlist}{\setcounter{enumi}{0} \renewcommand{\labelenumi} {\addtocounter{enumi}{1}\arabic{enumi}.}} \newcommand{\listtype}[1]{#1} %Create the environment \newenvironment{multienumerate}[1][\regularlist]{% \listtype{#1} \begin{trivlist}% \setlength{\labelwidth}{18pt} \setlength{\labelsep}{5pt}% \setlength{\usedx}{\labelwidth}% \addtolength{\usedx}{\labelsep}% \setlength{\remainx}{\hsize}% \addtolength{\remainx}{-\usedx}% \setlength{\usedxx}{2\labelwidth}% \addtolength{\usedxx}{2\labelsep}% \setlength{\remainxx}{\hsize}% \addtolength{\remainxx}{-\usedxx}% \setlength{\usedxxx}{3\labelwidth}% \addtolength{\usedxxx}{3\labelsep}% \setlength{\remainxxx}{\hsize}% \addtolength{\remainxxx}{-\usedxxx}% \setlength{\usedxxxx}{4\labelwidth}% \addtolength{\usedxxxx}{4\labelsep}% \setlength{\remainxxxx}{\hsize}% \addtolength{\remainxxxx}{-\usedxxxx}% \setlength{\remainxox}{.666\remainxxx}% \addtolength{\remainxox}{\labelwidth}% \addtolength{\remainxox}{\labelsep}% \setlength{\remainxoxx}{.5\remainxxxx}% \addtolength{\remainxoxx}{\labelwidth}% \addtolength{\remainxoxx}{\labelsep}% \setlength{\itemindent}{0pt}}{\end{trivlist}} %%End of file `multienum.sty' \end{verbatim} \pagebreak \markboth{}{SAMPLE} \subsection*{Answers to Even Exercises} \begin{multicols}{2} \subsection*{Chapter 1} \subsection*{Section 1} \begin{multienumerate}[evenlist] \mitemxxx{2}{5}{$-4$} \mitemxxx{$x=1$}{$y=-7$}{$z=3$} \mitemxox{$x^2-3x+7=0$}{Yes} \mitemxxx{2}{5}{$-4$} \mitemxxx{$x=1$}{$y=-7$}{$z=3$} \mitemxox{$x^2-3x+7=0$}{Yes} \mitemxxx{2}{5}{$-4$} \mitemxxx{$x=1$}{$y=-7$}{$z=3$} \mitemxox{$x^2-3x+7=0$}{Yes} \mitemxxx{2}{5}{$-4$} \mitemxxx{$x=1$}{$y=-7$}{$z=3$} \mitemxxx{2}{5}{$-4$} \mitemxxx{$x=1$}{$y=-7$}{$z=3$} \mitemxxx{2}{5}{$-4$} \end{multienumerate} \subsection*{Section 2} \begin{multienumerate}[evenlist] \mitemxxo{Yes}{$3x^2+x=-2$} \mitemx{If $x=1$, the only solution is $y=3$.} \mitemxxx{$x=1$}{$y=-7$}{$z=3$} \mitemxxx{Yes}{No}{No} \mitemxxx{2}{5}{$-4$} \mitemxox{$x^2-3x+7=0$}{Yes} \mitemxxx{2}{5}{$-4$} \mitemxxx{$x=1$}{$y=-7$}{$z=3$} \mitemxox{$x^2-3x+7=0$}{Yes} \mitemxxx{2}{5}{$-4$} \newsavebox{\diagonal} \savebox{\diagonal}{\setlength{\unitlength}{.6pt} \begin{picture}(70,70)(0,0) \put(0,0){\framebox(70,70){}} \put(35,5){\vector(0,1){60}} \put(5,35){\vector(1,0){60}} \put(10,10){\line(1,1){50}} \end{picture}} \mitemxx{\vskip0pt\usebox{\diagonal}}{\vskip0pt\usebox{\diagonal }} \mitemx{Johnie should sell 3 red marbles, buy 2 white marbles, and keep the rest.} \mitemx{Sarah should buy 2 pounds of squash, 3 pounds of potatoes, and 4 pounds of fish.} \end{multienumerate} \subsection*{Answers to Odd Exercises} \subsection*{Chapter 2} \subsection*{Section 1} \begin{multienumerate}[oddlist] \mitemxxx{Yes}{No}{No} \mitemxxxx{3}{5}{2}{$-8$} \mitemxxox{7}{$2x-3y=6$}{1} \mitemxxx{2}{5}{$-4$} \mitemxxx{$x=1$}{$y=-7$}{$z=3$} \mitemxox{$x^2-3x+7=0$}{Yes} \mitemxxx{2}{5}{$-4$} \mitemxxx{$x=1$}{$y=-7$}{$z=3$} \mitemxxx{2}{5}{$-4$} \mitemxxx{$x=1$}{$y=-7$}{$z=3$} \mitemxxx{$x=1$}{$y=-7$}{$z=3$} \mitemxxx{2}{5}{$-4$} \end{multienumerate} \end{multicols} \end{document} \noindent \rule{\hsize}{2pt} \begin{multienumerate} \mitemxxxx{Not}{Linear}{Not}{Quadratic} \mitemxxxo{Not}{Linear}{No; if $x=3$, then $y=-2$.} \mitemxx{$(x_1,x_2)=(2+\frac{1}{3}t,t)$ or $(s,3s-6)$}{$(x_1,x_2,x_3)=(2+\frac{5}{2}s-3t,s,t)$} \mitemx{$(x_1,x_2,x_3,x_4)= (\frac{1}{4}+\frac{5}{4}s+\frac{3}{4}t-u,s,t,u)$ or $(s,t,u,\frac{1}{4}-s+\frac{5}{4}t+\frac{3}{4}u)$} \mitemxxxx{$(2,-1,3)$}{None}{$(2,1,0,1)$}{$(0,0,0,0)$} \end{multienumerate} \noindent \rule{\hsize}{1pt}