4

I'm a fairly new LaTeX user, so please excuse me if this is a simple newbie question.

I am using the exam package to create, well, an exam. I use both the \choices and \oneparchoices environments and I would like them to be aligned instead of the choices ones being far more indented. This MWE should illustrate my point:

\documentclass{exam}

\begin{document}

\begin{questions}

   \question
    Question 1

   \begin{oneparchoices}
       \correctchoice Answer 1
       \choice Answer 2
       \choice Answer 3
   \end{oneparchoices}

   \question
   Question 2

   \begin{choices}
    \correctchoice Answer 1
    \choice Answer 2
    \choice Answer 3
   \end{choices}

   \end{questions}

 \end{document}

This is what I get.

I'm sure the more experienced users can solve this easily, but I'm stuck.

  • did you try the \noindent command after \begin{choice}? – Yorgos Jan 18 at 8:21
  • @Yorgos: As choices is a list environment \noindent will not work. The indention is done using \leftmargin not \indent. – Martin Scharrer Jan 18 at 8:50
  • @Yorgos. Yes, I tried that. Should have mentioned it. – andhewoulddarkenthememory Jan 18 at 9:04
3

Having a look at the source code of the exam class shows me that the left margin (realized as \leftmargin in LaTeX) is set by choices using a hard coded line \settowidth{\leftmargin}{W.\hskip\labelsep\hskip 2.5em}%, i.e. it is set to the width of W. + labelsep + 2.5em (em is relative to your font size).

I don't see an easy way to change that as there is no setting for this provided. You only could copy the definition of choices from exam.cls into your document, between \makeatletter and \makeatother, and change the above line to \setlength{\leftmargin}{<your prefered length>}. I would recommend here 15pt which is the normal \parindent. Your can't apparently not use \parindent directly as the list environment in choices seems to redefine it.
You also need to change \newcommand to \renewcommand of course.

\documentclass{exam}

\makeatletter
% from exam.cls, line 4107:
\renewenvironment{choices}%
  {\list{\choicelabel}%
     {\usecounter{choice}\def\makelabel##1{\hss\llap{##1}}%
       \setlength{\leftmargin}{15pt}%
       \def\choice{%
         \if@correctchoice
           \color@endgroup
           \endgroup
         \fi
         \item
         \do@choice@pageinfo
       } % choice
       \def\CorrectChoice{%
         \if@correctchoice
           \color@endgroup
           \endgroup
         \fi
         \ifprintanswers
           \ifhmode \unskip\unskip\unvbox\voidb@x \fi
           \begingroup \color@begingroup \@correctchoicetrue
           \CorrectChoice@Emphasis
         \fi
         \item
         \do@choice@pageinfo
       } % CorrectChoice
       \let\correctchoice\CorrectChoice
       \labelwidth\leftmargin\advance\labelwidth-\labelsep
       \topsep=0pt
       \partopsep=0pt
       \choiceshook
     }%
  }%
  {\if@correctchoice \color@endgroup \endgroup \fi \endlist}
\makeatother

\begin{document}

\begin{questions}

   \question
    Question 1

   \begin{oneparchoices}
       \correctchoice Answer 1
       \choice Answer 2
       \choice Answer 3
   \end{oneparchoices}

   \question
   Question 2

   \begin{choices}
    \correctchoice Answer 1
    \choice Answer 2
    \choice Answer 3
   \end{choices}

   \end{questions}

 \end{document}

enter image description here

  • Thanks a lot! That is well beyond my current knowledge of LaTeX. But with the code you provided I got it to work. :) – andhewoulddarkenthememory Jan 18 at 9:05

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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