Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

migrated from meta.tex.stackexchange.com Nov 5 '12 at 7:01

This question came from our discussion, support, and feature requests site for users of TeX, LaTeX, ConTeXt, and related typesetting systems.

1 Answer 1

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}
share|improve this answer
    
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 '12 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. –  Peter Grill Nov 6 '12 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 '12 at 12:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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