Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have tried using the following code:

\documentclass[12pt]{exam}
\CorrectChoiceEmphasis{\mbox{}}
\begin{document}
\begin{questions}
\question Who is an idot? 
\begin{choices}
\choice Not the writer of this post
\CorrectChoiceEmphasis The writter of this post
\end{choices}
\end{questions}
\end{document}
share|improve this question
    
By box you mean put a frame around the correct answer? –  cgnieder Nov 8 '12 at 9:54
    
@cgnieder Frame, means to have a border on all 4 sides like a square around the correct answers, then yes. –  MaoYiyi Nov 8 '12 at 9:56
add comment

2 Answers

up vote 6 down vote accepted

Here are a couple of methods:

The code:

\documentclass[12pt]{exam}
\newcommand{\mycorrectchoice}[1]{\CorrectChoice \fbox{#1}}

\usepackage{tikz}
\usetikzlibrary{calc,shapes}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\newcommand{\DrawSmartBox}[1][red]{%
    \tikz[overlay,remember picture]{
    \draw[#1]
      ($(bl)+(-1.75em,1em)$) rectangle
      ($(br)+(0.2em,-0.4em)$);}
}

% \MyCorrectSmartChoice:
% #1 optional argument: aspect customization
% #2 mandatory argument: the answer
\newcommand{\MyCorrectSmartChoice}[2][black]{\CorrectChoice \tikzmark{bl}#2\tikzmark{br}\DrawSmartBox[#1]}

\begin{document}
\begin{questions}
\question Who is an idot? 
\begin{choices}
\choice Not the writer of this post
\mycorrectchoice{The writter of this post}
\choice Who read this post
\end{choices}
\question Who is an idot? 
\begin{choices}
\choice Not the writer of this post
\MyCorrectSmartChoice[thick,rounded corners,red]{The writter of this post}
\choice Who read this post
\end{choices}
\end{questions}

\end{document}

The result:

enter image description here

Notice that the example requires two compilation runs because of the \tikzmark macro; furthermore, this approach allows to customize the aspect of the box, as did in the example.

share|improve this answer
    
I got emp.tex:0:No file temp.aux. temp.tex:23:Undefined control sequence. \mycorrectchoice{The writter of this post} temp.tex:29:Undefined control sequence. ...rrectSmartChoice{The writter of this post} temp.tex:0: Label(s) may have changed. Rerun to get cross-references right. –  MaoYiyi Nov 8 '12 at 12:24
    
@MaoYiyi: you should compile twice because of the tikzmark macro. Does it solve the problem? –  Claudio Fiandrino Nov 8 '12 at 13:16
    
I just push the button to make a pdf. How does one compile? I use Kile to write my latex. –  MaoYiyi Nov 8 '12 at 13:30
    
Just push it twice and check that your auxiliary file are not deleted between the two runs. :) –  Claudio Fiandrino Nov 8 '12 at 13:37
add comment

Here is a modification of Claudio's answer. With this modification, if you don't use the answers option of the exam class the correct answer is not boxed, you can give the exam to your students, the result is:

enter image description here

If the answers option is used (the syntax is

\documentclass[answers]{exam}

) then the correct answers are boxed. The result is:

enter image description here

The code is

\documentclass[12pt]{exam} %Use the answers option to box correct answers

\usepackage{tikz}
\usetikzlibrary{calc,shapes}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\newcommand{\DrawSmartBox}[1][red]{%
    \tikz[overlay,remember picture]{
    \draw[#1]
      ($(bl)+(-1.75em,1em)$) rectangle
      ($(br)+(0.2em,-0.4em)$);}
}

%Here is the modification
\ifprintanswers
% \MyCorrectSmartChoice:
% #1 optional argument: aspect customization
% #2 mandatory argument: the answer
\newcommand{\MyCorrectSmartChoice}[2][black]{\CorrectChoice \tikzmark{bl}#2\tikzmark{br}\DrawSmartBox[#1]}
\else
\newcommand{\MyCorrectSmartChoice}[2][black]{\CorrectChoice #1}
\fi

\begin{document}
\begin{questions}
\question Who is an idiot? 
\begin{choices}
\choice Not the writer of this post
\MyCorrectSmartChoice[thick,rounded corners,red]{The writer of this post}
\choice Who read this post
\end{choices}
\end{questions}

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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