15

I want to create an multiple choices question with this indenting format

1. ########
   A. ###
   B. ###
   C. ###
2. ########
   ########
   A. ###
   B. ###
   C. ###

The choices have same indentation as the question text.

But, using the default exam documentclass, I get this format

1. ########
     A. ###
     B. ###
     C. ###
2. ########
   ########
     A. ###
     B. ###
     C. ###

Hence, I try to set the \leftmargin to 0pt inside the choices environment to get what I want.

\documentclass{exam}
\begin{document}
\begin{questions}
  \question
  How old are you?
  \begin{choices}
    \setlength{\leftmargin}{0pt}
    \choice 14
    \choice 17
    \choice 19
    \choice 20
    \choice 23
  \end{choices}
\end{questions}
\end{document}

But, It get nowhere.

So, What is the right way to set indentation of choice in exam documentclass?

3 Answers 3

11

Following Section 4.10 of the exam documentation, I believe you are looking for choiceshook, which can be used as follows, for example

\renewcommand{\questionshook}{%
    \setlength{\leftmargin}{30pt}%
}
\renewcommand{\choiceshook}{%
    \setlength{\leftmargin}{50pt}%
}

Here is a complete MWE- I loaded the geometry package with showframe=true just for demonstration.

% arara: pdflatex
% !arara: indent: {overwrite: true}
\documentclass{exam}
\usepackage[showframe=true]{geometry}

\renewcommand{\questionshook}{%
    \setlength{\leftmargin}{30pt}%
}
\renewcommand{\choiceshook}{%
    \setlength{\leftmargin}{50pt}%
}
\begin{document}
\begin{questions}
    \question
    How old are you?
    \begin{choices}
        \choice 14
        \choice 17
        \choice 19
        \choice 20
        \choice 23
    \end{choices}
\end{questions}
\end{document}

For reference, here's a quote from the exam documentation

The exam document class defines these as follows:

\newcommand{\questionshook}{} 
\newcommand{\partshook}{}
\newcommand{\subpartshook}{} 
\newcommand{\subsubpartshook}{}
\newcommand{\choiceshook}{} 
\newcommand{\checkboxeshook}{} 

Thus, the default is that these commands have no effect, but you can change any of them with a \renewcommand command.

2
  • 2
    changing \setlength{\leftmargin}{50pt}% to \settowidth{\leftmargin}{W.\hskip\labelsep\hskip 0em} gives the desired result of indenting that I want. Though I'm pretty confused with the second argument of the \settowidth above.
    – Mas Adit
    Apr 13, 2013 at 14:52
  • I also wasn't able to get the solution here to work, but did get the one in your comment @MasAdit to work. I have no clue why though
    – J M
    Mar 26, 2017 at 21:33
5

Try this and see

\uplevel{
\begin{choices}
    \choice 
    \choice 
    \choice 
    \choice 
\end{choices}}
6
  • Welcome to TeX.SX! To add syntax highlighting in a post, you can select the code and click the button marked {} above the text field. Aug 8, 2014 at 6:40
  • Please add a document around your solution and provide a screen shot, in order to make this a real answer
    – user31729
    Aug 8, 2014 at 7:01
  • @ChristianHupfer I'm not sure a screenshot is always required, but I agree that some explanation should be given.
    – Joseph Wright
    Aug 8, 2014 at 7:34
  • @JosephWright: If I would be the OP (although the question is 'old') I would prefer a screen shot as a quick check if this provided solution fulfills the request. That's why I asked about the screen shot.
    – user31729
    Aug 8, 2014 at 15:08
  • @ChristianHupfer 'Prefer' certainly: I was trying to say that one is not 'required' for an answer to be valid
    – Joseph Wright
    Aug 8, 2014 at 15:10
-1
  1. find your "exam.cls" on your latex folder.

  2. open it,

change \settowidth{\leftmargin}{W.\hskip\labelsep\hskip 2.5em}% to \settowidth{\leftmargin}{W.\hskip\labelsep\hskip 0em}%

  1. save.
1
  • 1
    It's not a good idea to change the original class (.cls). You can add the necessary code in your own document.
    – CarLaTeX
    Dec 8, 2021 at 5:28

You must log in to answer this question.

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