8

The following code gives a way to produce Multiple Choices Questions. This solution comes from here.

I would like to have the possibility to display the choices in 2 or 3 columns by giving one optional argument. Is there a way to do that ?

\documentclass[a4,12pt]{article}
    \usepackage[utf8x]{inputenc}
    \usepackage{amsmath}

    \newcounter{choice}
    \renewcommand\thechoice{\Alph{choice}}
    \newcommand\choicelabel{\thechoice)}

    \newenvironment{choice}{%
        \list{\choicelabel}{%
            \usecounter{choice}\def\makelabel##1{\hss\llap{##1}}%
            \settowidth{\leftmargin}{W.\hskip\labelsep\hskip 2.5em}%
            \def\choice{%
                \item
            } % choice
            \labelwidth\leftmargin\advance\labelwidth-\labelsep
            \topsep=0pt
            \partopsep=0pt
        }%
    }{\endlist} 

\begin{document}
Which fractions are reduced ?

\begin{choice}
    \choice $\dfrac{4}{7}$
    \choice $\dfrac{8}{24}$
    \choice $\dfrac{44}{121}$
    \choice $\dfrac{9}{11}$
\end{choice}

\end{document}
projetmbc
  • 13,315

1 Answers1

13

Not exactly what you're looking for, but approximately as easy to use. A choice environment and command is probably overkill compared to customizing an enumerated list with the enumitem package (reworked from earlier version to match preferred semantics):

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{enumitem}
\usepackage{multicol}

\newlist{choices}{enumerate}{1}
\setlist[choices]{label*=(\Alph*)}
\newcommand{\choice}{\item}

\SetEnumitemKey{twocol}{
  before=\raggedcolumns\begin{multicols}{2},
  after=\end{multicols}}

\SetEnumitemKey{threecol}{
  before=\raggedcolumns\begin{multicols}{3},
  after=\end{multicols}}

\begin{document}
Which fractions are reduced (one column)?
\begin{choices}
   \choice $\dfrac{4}{7}$
   \choice $\dfrac{8}{24}$
   \choice $\dfrac{44}{121}$
   \choice $\dfrac{9}{11}$
\end{choices}

Which fractions are reduced (two columns)?
\begin{choices}[twocol]
   \choice $\dfrac{4}{7}$
   \choice $\dfrac{8}{24}$
   \choice $\dfrac{44}{121}$
   \choice $\dfrac{9}{11}$
\end{choices}

Which fractions are reduced (three columns)?
\begin{choices}[threecol]
   \choice $\dfrac{4}{7}$
   \choice $\dfrac{8}{24}$
   \choice $\dfrac{44}{121}$
\end{choices}

\end{document}
Mike Renfro
  • 20,550
  • Thanks for this begin of solution. I prefer to use one special environment for semantic reasons. – projetmbc Mar 03 '12 at 22:47
  • Reworked to match your semantics. – Mike Renfro Mar 04 '12 at 01:30
  • @MikeRenfro How to make it numbering along the rows rather than numbering down the columns? Thanks. – Z.H. Oct 04 '13 at 08:57
  • If all the answers can fit on one line, you could just increase the number of columns in the multicol environment. The only other easy way (for me) would be to use enumitem's inline list options. You won't get a row/column layout with that, though. There may be some TikZ routes, or someone might have a way of building a table one cell at a time, automatically inserting row breaks as needed. If that's more of what you need, I'd say it's worth asking a separate question. – Mike Renfro Oct 05 '13 at 13:50
  • @MikeRenfro How can I make this 2 columns thing work in document class exam? – Mathematics Jul 27 '21 at 06:22
  • 1
    Looks like the exam class already defines a choices environment, so if you rename this answer's choices environment and choice command to something else, it appears to work fine. – Mike Renfro Jul 30 '21 at 00:20