# enumerate in multicols

The following image illustrates what am looking for:

Essentially I want the numbering to occur as shown above but using the multicol and enumitem package. But when I try it by using the following code:

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{enumitem,multicol}
\begin{document}
\begin{enumerate}
\item Evaluate each of the following if $x$ is a non-zero real number.
\begin{multicols}{2}
\begin{enumerate}[itemsep=1cm]% The item sep is my choice here.
\item $\dfrac{|x|}{x}$
\item $\dfrac{x}{|x|}$
\item $\dfrac{|-x|}{-x}$
\item $|x|-|-x|$
\end{enumerate}
\end{multicols}
\end{enumerate}
\end{document}


I get:

Essentially, I want the (b) to be where the (c) is. I know this has been done but I can't seem to find it.

-
+1 An ugly way round it- use two sets of multicols and resume the enumerate, but hopefully someone has a more elegant way –  cmhughes Aug 20 '12 at 20:14
@cmhughes yeah ugly indeed :-) –  azetina Aug 20 '12 at 20:18
–  David Carlisle Aug 20 '12 at 20:22
@DavidCarlisle Nice, I agree it is similar to my question but am not looking for a mathmode environment rather some listing method such as the enumitem package along with the multicol package. –  azetina Aug 20 '12 at 20:29
Not sure why you pre-determine the needed packages, rather than just the outcome, but whatever. Your example text was a sequence of math displays each labelled with a counter, which is same as the other question. multicol reading order is down the columns, if you want a reading order that is across the page, you don't want multicol. Or you want to disable all its features which is harder. –  David Carlisle Aug 20 '12 at 20:33

Here is an option using the defined \newitem command. The contents is set in a \parbox that naturally flows left-to-right, providing the enumeration in the style you're after:

\documentclass{article}
\usepackage{amsmath,amssymb}% http://ctan.org/pkg/{amsmath,amssymb}
\usepackage{enumitem,multicol,setspace}% http://ctan.org/pkg/{enumitem,multicol,setspace}
\newcounter{subenum}[enumi]
\renewcommand{\thesubenum}{\alph{subenum}}
\newcommand{\newitem}[1]{%
\refstepcounter{subenum}%
\parbox{\dimexpr.5\linewidth-.5\columnsep}{%
\makebox[\labelwidth][r]{(\thesubenum)\hspace*{\labelsep}}%
#1}\hfill%
}
\begin{document}
\begin{enumerate}[start=8]
\item Evaluate each of the following if $x$ is a non-zero real number.
\begin{multicols}{2}
\begin{enumerate}[itemsep=1cm]% The item sep is my choice here.
\item $\dfrac{|x|}{x}$
\item $\dfrac{x}{|x|}$
\item $\dfrac{|-x|}{-x}$
\item $|x|-|-x|$
\end{enumerate}
\end{multicols}
\item Evaluate each of the following if $x$ is a non-zero real number.\par
\setstretch{3}%
\newitem{$\dfrac{|x|}{x}$}
\newitem{$\dfrac{x}{|x|}$}
\newitem{$\dfrac{|-x|}{-x}$}
\newitem{$|x|-|-x|$}
\end{enumerate}
\end{document}


Spacing consideration is provided by setspace and can be tweaked (also removing some additional "\topsep" white space, if needed).

For a slightly more automated approach to changing the number of columns, add

\usepackage[nomessages]{fp}% http://ctan.org/pkg/fp


to your document preamble, and use

\FPeval\thecolwidth{round(1/4:4)}% Specify number of columns -> column width
\newcommand{\newitem}[1]{%
\refstepcounter{subenum}%
\parbox{\dimexpr\thecolwidth\linewidth-.5\columnsep}{%
\makebox[\labelwidth][r]{(\thesubenum)\hspace*{\labelsep}}%
#1}\hfill%
}


as your definition for \newitem. Modify 1/4 to 1/<col nums> to increase the number of columns.

-
What if I wanted three columns? Or maybe 4 columns? Do I need to edit \dimexpr.5\linewidth-.5\columnsep? –  azetina Aug 21 '12 at 15:39
@azetina: Correct. For 3 columns, you could use \dimexpr.3333\linewidth-.5\columnsep, while 4 columns could use \dimexpr.25\linewidth-.5\columnsep. –  Werner Aug 21 '12 at 15:58
Can one make the calculations like \def\newnum\dimexpr 1/#1 \relax? or something like that to avoid the decimals? –  azetina Aug 21 '12 at 16:00
@azetina: I've added some calculations to the post, referencing the fp package for convenient calculations of the column widths. –  Werner Aug 21 '12 at 16:13

\documentclass{article}
\usepackage{amsmath,amssymb}
%\tracingall
\def\horizlist#1#2#3{%
\setcounter{enumi}{0}%
#3%
\flushleft
\dimen0 \linewidth
\divide\dimen0 by #1\relax
\def\item{\hfil\egroup\penalty50 \hfill
\refstepcounter{enumi}%
\leavevmode\hbox to \dimen0 \bgroup\space(\theenumi)\space}%
\leavevmode\bgroup\hskip 0pt plus -1fill }

\def\endhorizlist{\hfil\egroup\endflushleft}

\begin{document}
\begin{enumerate}
\item Evaluate each of the following if $x$ is a non-zero real number.
\begin{horizlist}{2}{1cm}{\renewcommand\theenumi{\alph{enumi}}}
\item $\dfrac{|x|}{x}$
\item $\dfrac{x}{|x|}$
\item $\dfrac{|-x|}{-x}$
\item $|x|-|-x|$
\end{horizlist}
\end{enumerate}
\end{document}


To see what is happening here, if you want the numbering to go right-left before down that is normal paragraph word order so the thing to do is just make a series of boxes of fixed width If they are (say) 1/3 of text width and you makes a paragraph of such boxes in a flush left paragraph then Tex will naturally wrap the paragraph with three boxes on a line and they will align vertically as they are all the same width. the rest of the code just increments a counter and puts (\the...) at the front of the box, and hides the \makebox[0.3\textwidth]{...} syntax to use the standard \item syntax so it is easy to switch between list types.

In other words compare to the following which is the same apart from cosmetic syntax changes.

\documentclass{article}

\begin{document}
\begin{flushleft}

\makebox[.3\textwidth][l]{one one}
\makebox[.3\textwidth][l]{two 2 two 2 two}
\makebox[.3\textwidth][l]{three three 3}
\makebox[.3\textwidth][l]{4 4 4 4 4 }
\makebox[.3\textwidth][l]{fifth box}
\makebox[.3\textwidth][l]{number 6}
\makebox[.3\textwidth][l]{7 7 7 7 }
\makebox[.3\textwidth][l]{eight}
\makebox[.3\textwidth][l]{nine nine}
\makebox[.3\textwidth][l]{10}

\end{flushleft}
\end{document}


Even though the result has the appearance of being in three columns, it is just a typeset paragraph with the alignment being automatic as each "word" in the paragraph is a box of equal size.

-
Could you comment in your code what it is doing? I sort of get but I need to be certain if am to use it. I am learning :-) –  azetina Aug 21 '12 at 15:41
comment was too long, I'll add it to the answer –  David Carlisle Aug 21 '12 at 15:51

Here is a boring one that uses the resume functionality of enumitem package. It's not the most efficient as the code starts stops the enumerate environment too much. But the result is acceptable visually. You can introduce all kinds of additional tweaks since it's just a tabular environment.

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{enumitem}
\newcommand{\Choices}[4]{\begin{tabular}{p{0.5\textwidth} p{0.5\textwidth}}
\begin{enumerate*}[series=lafter]
\item #1
\end{enumerate*} &%
\begin{enumerate*}[resume=lafter]
\item #2
\end{enumerate*} \\[2\baselineskip]
\begin{enumerate*}[resume=lafter]
\item #3
\end{enumerate*} &%
\begin{enumerate*}[resume=lafter]
\item #4
\end{enumerate*}
\end{tabular}}

\begin{document}
\begin{enumerate}
\item Evaluate each of the following if $x$ is a non-zero real number.

\Choices{$\dfrac{|x|}{x}$}{$\dfrac{x}{|x|}$}{$\dfrac{|-x|}{-x}$}{$|x|-|-x|$}

\item Evaluate each of the following if you can.

\Choices{This question is not answerable (is that a real word?)}
{This question does not have any correct answer}
{$\int_0^\pi{\tan\sqrt\theta d\theta}$}
\end{enumerate}
\end{document}


-
I guess this is limited to the number of inputs possible; like in your case we are looking at four options only. Say I wanted 3 columns and 12 such problems, what will I do then? Surely I can edit your code and input the amount I want but I guess its a bit cumbersome :-) Nice way. Learnt about lafter. –  azetina Aug 21 '12 at 15:35
@azetina Note that, it only solves the given problem :) You can make it flexible by allocating rows and numbers first and supplying an array of answers, if you wish. By the way lafter is just the name of the list, you are free to choose anything. –  percusse Aug 21 '12 at 16:56
Yah I know, I actually meant the series idea. –  azetina Aug 21 '12 at 18:55

Here is another solution which does not have to define a new \item command.

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amssymb}%for \dfrac
\usepackage[inline]{enumitem}%for enviroment enumerate*
\usepackage{tabto}%for \tab and \NumTabs
\begin{document}
\begin{enumerate}[start=44]
\item Evaluate each of the following if $x$ is a non-zero real number.\\
\NumTabs{2}
\begin{enumerate*}[itemjoin=\tab]
\item $\dfrac{|x|}{x}$
\item $\dfrac{x}{|x|}$
\item $\dfrac{|-x|}{-x}$
\item $|x|-|-x|$
\end{enumerate*}
\end{enumerate}
\end{document}


Here is what the solution looks like

The command \NumTabs{2} is a to specify that there should be two tab stops, this uses the current value of \linewidth to create tab stops for the rest of the document.
Thus if the line width changes and if you need to use tabs, then it is best to rewrite \NumTabs{2}. The command \tab makes the text that follows it to be positioned at the next tab stop.

The environment enumerate* is used to create inline lists, thus I put a \\ after "is a non-zero real number." The option itemjoin is used to specify what comes between the items, in this case the command \tab comes in between each item.

-

This is easy with the exsheets package and the tasks package. The following example hopefully is self-explaining:

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage{mathtools}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}

\usepackage{exsheets}% loads the tasks' package
\SetupExSheets{
}
counter-format = tsk[a]. ,
label-format = \sffamily\itshape\bfseries
}

\setcounter{question}{43}% only for this example

\begin{document}

\begin{question}
Evaluate each of the following if $x$ is a non-zero real number.
\task $\dfrac{\abs{x}}{x}$
\task $\dfrac{x}{\abs{x}}$
\task $\dfrac{\abs{-x}}{-x}$
\task $\abs{x}-\abs{-x}$
`