0

I am preparing a multiple choice exam template, mainly with \oneparchoices in exam class. I want to change \oneparchoices (or using any other method), so that the answers always appear in three rows ( will be more clear with the MWE). Using the suggestion given in a previous discussion "Centering Answers in Exam Class", I did some work:

\documentclass[noaddpoints,12pt]{exam}
\usepackage{amsmath}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgf}
\footer{}{\thepage}{}
\usepackage{graphicx}
\usepackage{multicol}
\setlength{\columnsep}{1cm}
\setlength{\multicolsep}{1.2em}
\usepackage{color}
\usepackage{wrapfig}
\setlength{\columnseprule}{0.5pt}
\def\columnseprulecolor{\color{black}}
\usepackage{tasks}

\newenvironment{oneparchoicescentering}{
 \begingroup
 \leftskip=-0cm plus .5fil%                                                                                                                                                                           
 \rightskip=0cm plus -.5fil%                                                                                                                                                                          
 \parfillskip=0cm plus 1fil\relax
 \begin{oneparchoices}
}{
 \end{oneparchoices}
 \par
 \endgroup
}
\begin{document}
\noindent\framebox[\textwidth][s]{Test No: 001\hfill Topic: Elements}
\begin{multicols}{2}
\begin{questions}

\noindent\begin{minipage}{\linewidth}
\question Which one of the entries does not fit with the others?

\begin{oneparchoicescentering}
    \CorrectChoice $\frac{\frac{1}{2}+1}{2+\pi}+1$
    \choice $\sqrt{3\pi}$
    \choice $e^x$
    \choice Text
    \choice $\int xdx$
\end{oneparchoicescentering}
\vspace{3cm}
\end{minipage}

\noindent\begin{minipage}{\linewidth}
\question Which one of the entries does not fit with the others?

\begin{oneparchoicescentering}
    \CorrectChoice aaaaaaaaaa
    \choice bbbbbbbbbb
    \choice cccccccccc
    \choice dddddddddd
    \choice eeeeeeeeee
\end{oneparchoicescentering}
\vspace{3cm}
\end{minipage}
\end{questions}
\end{multicols}
\end{document}

The result is: enter image description here

Now, I want to make the following changes:

  1. As you can see, depending on the length of the answers, they appear in two or three rows. My purpose is to get the answers always in three rows (as in the second question of MWE), how can I do that ?
  2. The mathematical terms (especially the fraction) appear too small. Is there any way to avoid this ? (Probably I will need to increase the vertical spacing between the answer lines.)
  3. In the second question of MWE, choice B and choice D are not aligned. How can I avoid this ? (I believe that solving my first question will also solve this one, but I wanted to mention it.)

Thank you in advance, Cheers.

3
  • For 2. you can type \dfrac{}{}
    – Sigur
    Jun 9, 2018 at 23:18
  • In 3. they look aligned to me. D is wider than B. But the periods are aligned.
    – Sigur
    Jun 9, 2018 at 23:19
  • Since the answers are not the same width and are right justified, B. and D. will never be aligned. You might set something up, but you would have to abandon the exam class protocol. Jun 11, 2018 at 18:25

1 Answer 1

1

This is as far as I got. The problem is that the answer is not an argument of \choice. \CorrectChoice puts the answer into a group and relies on the next \choice or \end{oneparchoice} to add the \endgroup, nor is it clear what the group does.

Anyway, this shows an ugly way to achieve what you want. I removed the penalty from the first line of the paragraph to align the columns. Maybe someone else can figure out a way to incorporate the \makebox into \choice and \CorrectChoice.

\documentclass[noaddpoints,12pt]{exam}
\usepackage{amsmath}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgf}
\footer{}{\thepage}{}
\usepackage{graphicx}
\usepackage{multicol}
\setlength{\columnsep}{1cm}
\setlength{\multicolsep}{1.2em}
\usepackage{color}
\usepackage{wrapfig}
\setlength{\columnseprule}{0.5pt}
\def\columnseprulecolor{\color{black}}
\usepackage{tasks}

\makeatletter
\renewenvironment{oneparchoices}%
  {%
    \setcounter{choice}{0}%
    \def\choice{%
      \if@correctchoice \endgroup \fi
      \refstepcounter{choice}%
      \ifnum\value{choice}>1\relax
        %\penalty -50\hskip 1em plus 1em\relax
      \fi
      \choicelabel
      % No need to put the following into a token string; we just put
      % the choicelabel onto the page, so we're at the spot whose page
      % number we want to record:
      \questionobject@pluspagecheck
      \nobreak\enskip
    }% choice
    \def\CorrectChoice{%
      \if@correctchoice \endgroup \fi
      \refstepcounter{choice}%
      \ifprintanswers
        \begingroup \@correctchoicetrue 
        \CorrectChoice@Emphasis
      \fi
      \ifnum\value{choice}>1\relax
        %\penalty -50\hskip 1em plus 1em\relax
      \fi
      \choicelabel
      % No need to put the following into a token string; we just put
      % the choicelabel onto the page, so we're at the spot whose page
      % number we want to record:
      \questionobject@pluspagecheck
      \nobreak\enskip
    }% CorrectChoice
    \let\correctchoice\CorrectChoice
    \let\par\@empty
    % If we're continuing the paragraph containing the question,
    % then leave a bit of space before the first choice:
    \ifvmode\else\enskip\fi
    \ignorespaces
  }%
  {\if@correctchoice \endgroup \fi}
\makeatother

\begin{document}
\noindent\framebox[\textwidth][s]{Test No: 001\hfill Topic: Elements}
\begin{multicols}{2}
\begin{questions}

\question Which one of the entries does not fit with the others?

\begin{oneparchoices}
    \makebox[0.5\linewidth][l]{\CorrectChoice $\dfrac{\frac{1}{2}+1}{2+\pi}+1$}
    \makebox[0.5\linewidth][l]{\choice $\sqrt{3\pi}$}
    \makebox[0.5\linewidth][l]{\choice $e^x$}
    \makebox[0.5\linewidth][l]{\choice Text}
    \makebox[0.5\linewidth][l]{\choice $\int xdx$}
\end{oneparchoices}
\vspace{3cm}
\question Which one of the entries does not fit with the others?

\begin{oneparchoices}
    \makebox[0.5\linewidth][l]{\CorrectChoice aaaaaaaaaa}
    \makebox[0.5\linewidth][l]{\choice bbbbbbbbbb}
    \makebox[0.5\linewidth][l]{\choice cccccccccc}
    \makebox[0.5\linewidth][l]{\choice dddddddddd}
    \makebox[0.5\linewidth][l]{\choice eeeeeeeeee}
\end{oneparchoices}
\vspace{3cm}
\end{questions}
\end{multicols}
\end{document}

demo


Beauty is in the eye of the beholder.

\documentclass[noaddpoints,12pt]{exam}
\usepackage{amsmath}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgf}
\footer{}{\thepage}{}
\usepackage{graphicx}
\usepackage{multicol}
\setlength{\columnsep}{1cm}
\setlength{\multicolsep}{1.2em}
\usepackage{color}
\usepackage{wrapfig}
\setlength{\columnseprule}{0.5pt}
\def\columnseprulecolor{\color{black}}
\usepackage{tasks}

\makeatletter
\renewenvironment{oneparchoices}%
  {%
    \setcounter{choice}{0}%
    \def\choice{%
      \if@correctchoice \endgroup \fi
      \refstepcounter{choice}%
      \ifnum\value{choice}>1\relax
        %\penalty -50\hskip 1em plus 1em\relax
      \fi
      \choicelabel
      % No need to put the following into a token string; we just put
      % the choicelabel onto the page, so we're at the spot whose page
      % number we want to record:
      \questionobject@pluspagecheck
      \nobreak\enskip
    }% choice
    \def\CorrectChoice{%
      \if@correctchoice \endgroup \fi
      \refstepcounter{choice}%
      \ifprintanswers
        \begingroup \@correctchoicetrue 
        \CorrectChoice@Emphasis
      \fi
      \ifnum\value{choice}>1\relax
        %\penalty -50\hskip 1em plus 1em\relax
      \fi
      \choicelabel
      % No need to put the following into a token string; we just put
      % the choicelabel onto the page, so we're at the spot whose page
      % number we want to record:
      \questionobject@pluspagecheck
      \nobreak\enskip
    }% CorrectChoice
    \let\correctchoice\CorrectChoice
    \let\par\@empty
    % If we're continuing the paragraph containing the question,
    % then leave a bit of space before the first choice:
    \ifvmode\else\enskip\fi
    \ignorespaces
  }%
  {\if@correctchoice \endgroup \fi}
\makeatother

\begin{document}
\noindent\framebox[\textwidth][s]{Test No: 001\hfill Topic: Elements}
\begin{multicols}{2}
\begin{questions}

\question Which one of the entries does not fit with the others?

\begin{oneparchoices}
    \makebox[0.5\linewidth][l]{\CorrectChoice $\dfrac{\frac{1}{2}+1}{2+\pi}+1$}
    \makebox[0.5\linewidth][r]{\choice $\sqrt{3\pi}$}
    \makebox[0.5\linewidth][l]{\choice $e^x$}
    \makebox[0.5\linewidth][r]{\choice Text}
    \makebox[\linewidth][c]{\choice $\int xdx$}
\end{oneparchoices}
\vspace{3cm}
\question Which one of the entries does not fit with the others?

\begin{oneparchoices}
    \makebox[0.5\linewidth][l]{\CorrectChoice aaaaaaaaaa}
    \makebox[0.5\linewidth][r]{\choice bbbbbbbbbb}
    \makebox[0.5\linewidth][l]{\choice cccccccccc}
    \makebox[0.5\linewidth][r]{\choice dddddddddd}
    \makebox[\linewidth][c]{\choice eeeeeeeeee}
\end{oneparchoices}
\vspace{3cm}
\end{questions}
\end{multicols}
\end{document}

demo

1
  • Yes, very impressive, but not really useful with a column oriented approach. Jun 11, 2018 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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