I need to have sections in an exam I am writing. The first 10 questions are multiple choice, which I would like to number simply 1-10. For the extended response, I would like to title the questions. Is there a way to do this in the exam class? Thank you for your help.
[Tex/LaTex] Titled & Untitled Questions in same document
exam
Related Solutions
1) I used xpatch
to fix the amount of space after each choice.
2) I renewed the \questionlabel
command for the first question. \phantom{}
reserves the space of the question number but it is not printed. I reset it it back to the class default before the section question.
\documentclass[addpoints]{exam}
\usepackage{xpatch}
% Need both to patch both instances (choice, correctchoice) in the oneparchoices environment.
% Unless there is a global replacement that works within an environment. I don't know.
% Replaces \hskip 1em with \hfill
\xpatchcmd{\oneparchoices}{\penalty -50\hskip 1em plus 1em\relax}{\hfill}{}{}
\xpatchcmd{\oneparchoices}{\penalty -50\hskip 1em plus 1em\relax}{\hfill}{}{}
\begin{document}
\begin{center}
\gradetable
\end{center}
\begin{questions}
\renewcommand\questionlabel{\phantom{\thequestion.}}
\titledquestion{\textbf{Multiple Choice}}[10]
What is the Capital of the United States in 1799?
\begin{oneparchoices}
\choice NY
\CorrectChoice Washington D.C.
\choice Chicago
\choice LA
\end{oneparchoices}
\renewcommand\questionlabel{\thequestion.}
%\setcounter{question}{0} %Uncomment if you want the first numbered question to start at 1.
\question[10]
What is the Capital of the United Kinddom in 1999?
\begin{oneparchoices}
\choice London
\CorrectChoice Washington D.C.
\choice Chicago
\choice Los Angeles
\end{oneparchoices}
\end{questions}
\end{document}
I made the following changes to exam.cls.
First I added a \printquestions option.
\newif\ifprintanswers
\printanswersfalse
\DeclareOption{answers}{\printanswerstrue}
\DeclareOption{noanswers}{\printanswersfalse}
% BEGIN EDIT %
\newif\ifprintquestions
\printquestionsfalse
\DeclareOption{yesquestions}{\printquestionstrue}
\DeclareOption{noquestions}{\printquestionsfalse}
% END EDIT %
Then later on
\def\printanswers{\printanswerstrue}
\def\noprintanswers{\printanswersfalse}
\def\printquestions{\printquestionstrue}
Next, I modify the solution environment. If I don't print the questions, then I wanted the solution environment to act as a \question.
\newenvironment{solution}[1][0pt]{%
\ifprintquestions % act as a solution
\@insolutiontrue % cancelled by the end of the environment
\@addpointsfalse % cancelled by the end of the environment
\ifprintanswers
\begingroup
\Solution@Emphasis
\begin{TheSolution}%
\else
\ifcancelspace
% Do nothing
\else
\par
\penalty 0
\vspace*{#1}%
\fi
\setbox\z@\vbox\bgroup
\fi
\else %act as a question
\question
\fi
}{%
\ifprintquestions %act as a solution
\ifprintanswers
\end{TheSolution}%
\endgroup
\else
\egroup
\fi
\fi
}%
Next, I add a quest environment which can be hidden. However, this would need to be used instead of \question.
\newenvironment{quest}[1][0pt]%
{%
\ifprintquestions % act as a question
\question
\else % don't show the question
%\par
%\vspace*{-9mm} %
\setbox\z@\vbox\bgroup
\fi
}{%
\ifprintquestions
% don't do anything
\else % hide the group
\egroup
\fi
}%
One annoying thing is that itemize lists, parts and subparts won't work in the environment I defined (I believe this is due to the \question call initializing some variables which I don't initialize. Therefore, I created some basic itemize list commands using the tabular environment.
% PART
\newcommand{\questp}[2]{%
\begin{tabular}{R{0.25cm} p{14.75cm}}
(#1) & #2 \\
\end{tabular}
{}
}
\usepackage{array,booktabs,ragged2e}
\newcolumntype{R}[1]{>{\RaggedLeft\arraybackslash}p{#1}}
\newcommand{\questsp}[2]{%
\hspace*{2em}\begin{tabular}{R{1cm} p{13.15cm}}
(#1) & #2 \\
\end{tabular}
{}
}
% SUBPART
\newcommand{\questssp}[1]{%
\hspace*{8em}\begin{tabular}{p{10.75cm}}
#1 \\
\end{tabular}
{}
}
Some more part commands could be defined like this.
\newcommand{\questpnob}[1]{%
\begin{tabular}{R{0.25cm} p{13.15cm}}
& #1 \\
\end{tabular}
{}
}
\newcommand{\questspnob}[1]{%
\hspace*{2em}\begin{tabular}{R{1cm} p{13.15cm}}
& #1 \\
\end{tabular}
{}
}
Best Answer
This is described in the documentation: You can use
\titledquestion
to assign a title to your question. In order for this title to be used in the question section, you also need to redefine the\qformat
. The format changes only apply to the questions that come after the\qformat
command, so you could first have the normal questions, then issue a\qformat
to get the titles. To revert back to the simple style, you can use\noqformat
.Here's a simple example: