2

Every two months I have to prepare the written statistics exams for my institute. In order to reduce the amount of printed pages I want to print the items of an answerlist horizontally. The package tasks does this job nicely but unfortunately I cannot use it directly.

We use the moodle multiple choice offline quiz module (mod/offlinequiz). The xml file (for moodle import) and the tex file are generated using the R package exams. It doesn't seem trivial to change the behavior of the R package to use the package tasks but I can easily redefine the existing answerlist environment.

What would be an elegant way to redefine \begin{answerlist} ... \end{answerlist} to be equivalent to \begin{tasks}(4) ... \end{tasks}? Hardcoding 4 columns wouldn't be an issue for me.

\documentclass{article}
\usepackage{tasks}

\begin{document}

% current definition of answerlist
\newenvironment{answerlist}{
    \renewcommand{\labelenumi}{(\alph{enumi})}
    \begin{enumerate}}
    {\end{enumerate}}

% Current output (generated by R package exams)
Choose the correct answer:
\begin{answerlist}
    \item[(a)] 447.2
    \item[(b)] 372.6
    \item[(c)] 298.1
    \item[(d)] 223.6
\end{answerlist}

% Desired output
Choose the correct answer:
\begin{tasks}(4)
    \task 447.2 
    \task 372.6 
    \task 298.1 
    \task 223.6 
\end{tasks}

\end{document}

2 Answers 2

1

With \RenewTasks the package provides already a way to do so. The reason why the renewenvironment approach doesn't work is explained in this post.

\documentclass{article}
\usepackage{tasks}

\begin{document}

% current definition of answerlist
\newenvironment{answerlist}{
    \renewcommand{\labelenumi}{(\alph{enumi})}
    \begin{enumerate}}
    {\end{enumerate}}

\RenewTasks[]{answerlist}[\item](4)
\begin{answerlist}
    \item[(a)] 447.2
    \item[(b)] 372.6
    \item[(c)] 298.1
    \item[(d)] 223.6
\end{answerlist}

\end{document}
0

You could use enumitem's inline lists.

\documentclass{article}

\usepackage[inline]{enumitem}

\makeatletter
    \newlist{@answerlist}{enumerate*}{1}
    \setlist[@answerlist]{
        label=(\alph*),
        before=\strut\hfil,
        itemjoin=\hfil,
    }
    \newenvironment{answerlist}{%
        \par\noindent
        \vskip 1ex plus 1ex minus .5ex
        \@answerlist
    }{%
        \end@answerlist
        \@@par
        \vskip 2ex plus 1ex minus 1ex
    }
\makeatother

\begin{document}

Choose the correct answer:
\begin{answerlist}
    \item 447.2
    \item 372.6
    \item 298.1
    \item 223.6
\end{answerlist}

\end{document}

MWE output

You must log in to answer this question.

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