2

I am trying to create a command namely \twoc to make a simple two column answer space for a specific question. The output should appear like this:

enter image description here

While my code for the .tex file that I will be doing should only be like this using the command \twoc:

Code

\Question What comes first?\\
\twoc
\text {apple}
\text {zebra}
\text {girrafe}
\text {dog}
\text {elephant}
\text {chicken}
\text {mouse}
\text {carabao}

Note

The command \twoc will automatically divide the text choices even. Example if text choices that are made was 8 then there should be 4 in each column.

1 Answer 1

2

With a slightly different syntax, you can use the multicol environment from the multicol package within an enumerated list. The Question environment below accepts an optional first parameter to control the number of columns (defaults to a single column if not specified):

enter image description here

Note:

  • The resume feature of the enumitem package is used to number the questions so that subsequent uses can have numbering continue on from the last question number.
  • I have used newtoggle from the etoolbox package as I prefer that syntax versus the \newif syntax. But if you don't want to include an additional package it should be pretty straightforward to adapt this to use \newif or some other conditional methods.
  • Similarly, \IfEq from the xstring package but should be able to do this without a package.

Code:

\documentclass{article}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{etoolbox}
\usepackage{xstring}

\newtoggle{UseMulticolumns}
\newenvironment{Question}[2][1]{%
    \IfEq{#1}{1}{%
        \global\togglefalse{UseMulticolumns}%
    }{%
        \global\toggletrue{UseMulticolumns}%
    }%
    \begin{enumerate}[series=QuestionList,label=\arabic*.,resume=*]
    \item #2
    \begin{enumerate}[label={\protect\rule{1.0em}{0.5pt}}]
    \iftoggle{UseMulticolumns}{\begin{multicols}{#1}}{}%
}{%
    \iftoggle{UseMulticolumns}{\end{multicols}}{}%
    \end{enumerate}%
    \end{enumerate}%
}

\begin{document}
\begin{Question}{Which comes first?}
    \item chicken
    \item egg
\end{Question}
\begin{Question}[2]{What comes first?}
    \item apple
    \item zebra
    \item girrafe
    \item dog
    \item elephant
    \item chicken
    \item mouse
    \item carabao
\end{Question}
\begin{Question}[3]{Who shot first?}
    \item Han
    \item Greedo
    \item Chewie
\end{Question}
\end{document}
3
  • when i build the code using Geany it did not compile. Instead, it underlines \begin{Question}{Which comes first?}. I changed the Question to questions already still it has errors.
    – Kayla
    Nov 5, 2012 at 23:58
  • @kayla: I am not familiar with Geany, but if there was a compilation error, then it would be helpful to know what the error was. You probably need to update packages. If you are on an older release, I would recommend that you install TexLive 2012. Nov 6, 2012 at 0:32
  • i already installed TexLive in Ubuntu. But i compile my work(the aaa.tex) using the document class that i have made (the myclass) that when I use it \documentclass{myclass} and I use geany - a text editor to compile my latex file. I installed geany's plugin that supports latex in ubuntu so I can build or compile the file in geany rather than in terminal.
    – Kayla
    Nov 6, 2012 at 12:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .