3

In the exam class there is an option to \printanswer. I have no problems with that, but when I work with a table I can not put the answers in the cells.

\documentclass[11pt,a4paper,addpoints,twoside]{exam} 
\noprintanswers
\printanswers
\setlength\answerclearance{1ex}
\renewcommand{\solutiontitle}{\textbf{Oplossing:}\par}
\pointpoints{punt}{punten}
\pointsinrightmargin
\boxedpoints
%\noboxedpoints
\begin{document}
\begin{questions}
\question[6] Vul aan met de juiste waarde 
\renewcommand{\arraystretch}{2} %verhoogt de rijhoogte
\begin{center}
\begin{tabular}{|c| c|  p{3cm}| p{3cm} | p{3cm}|}
\hline
a&b&7b&a+b&2a+b\\
\hline
\hline
5&2&&&\\
\hline
1&4&&&\\
\hline
\end{tabular}
\end{center}
\end{questions}
\end{document}

enter image description here

  • 1
    Please clarify what your problem is, actually. You don't use any solution and you have printanswers and noprintanswers switched on – LaRiFaRi Sep 15 '13 at 10:16
  • @LaRiFari I thougt my problem was clarified. I can not type \answerline so, I made the code without it. In the cells there should be the correct answer for 7 times b = 10. – Arne Timperman Sep 15 '13 at 14:34
  • Please edit you post to what you want, please! Do you want and empty line or the result? And why 10? – LaRiFaRi Sep 16 '13 at 6:46
2

This minimal working example works, if you toggle the line \noprintanswers. The increasing vertical spacing the boxes produce can maybe be customized. See http://www-math.mit.edu/~psh/exam/examdoc.pdf for further help on this topic.

\documentclass[%
,answers % switches on the use of solutions in general
,11pt
,a4paper
,addpoints
,twoside
]{exam} 
\usepackage{booktabs}

%\noprintanswers % toggle this for answers or no answers!

\pointsinrightmargin
\boxedpoints
%\noboxedpoints
\begin{document}
\begin{questions}
\question[6] Vul aan met de juiste waarde 
\renewcommand{\arraystretch}{2} %verhoogt de rijhoogte
\begin{center}
\begin{tabular}{c c | p{3cm} p{3cm}  p{3cm}}
\toprule
$a$&$b$&$7b$&$a+b$&$2a+b$\\
\midrule
5&2&\begin{solution}$14$\end{solution}&\begin{solution}$7$\end{solution}&\begin{solution}$12$\end{solution}\\
1&4&\begin{solution}$28$\end{solution}&\begin{solution}$5$\end{solution}&\begin{solution}$6$\end{solution}\\
\bottomrule
\end{tabular}
\end{center}
\end{questions}
\end{document}

Update

As mentioned by the OP in comments, a solution with answer lines is searched. They work as expected as shown in the following snippet:

\question[6] Vul aan met de juiste waarde
\renewcommand{\arraystretch}{2} %verhoogt de rijhoogte
\begin{center}
\begin{tabular}{c c | p{3cm} p{3cm}  p{3cm}}
\toprule
$a$&$b$&$7b$&$a+b$&$2a+b$\\
\midrule
5&2&\answerline&\answerline&\answerline\\
1&4&\answerline&\answerline&\answerline\\
\bottomrule
\end{tabular}
\end{center}
  • thanks for the effort, I really appreciate it, but it's not exact what I wanted. – Arne Timperman Sep 16 '13 at 19:13
  • 1
    OK, just clarify in your question and someone will try better. I am new to exam but you just told me, you were not able to type \answerline. What does that mean? You can't compile? Show as all info, we need. – LaRiFaRi Sep 16 '13 at 19:15
  • I will rewrite my problem tomorrow. Thanks for the help. – Arne Timperman Sep 17 '13 at 11:12
4

I made a new command \solutiontable{} which:

  • gives the same size of the cell if solutions are printed or not (it doesn't "wobble")
  • can be shaded by the command of the examclass: \shadedsolutions
  • can be colored by the command of the examclass: \SolutionEmphasis{\color{color}}
  • doesn't use \framedsolutions (don't know how to do that without changing the size of the solution)

Blockquote

\documentclass[11pt,a4paper]{exam}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{xcolor,colortbl}
\printanswers                         %toggle this on or of for solutions or not
\SolutionEmphasis{\color{red}}        %color font solutions
\unframedsolutions                    %Not necessary for table environment
\shadedsolutions                      %gives backgroundcolor to solutions
\begin{document}

\makeatletter%
\newcommand{\solutiontable}[1]{\ifprintanswers\begingroup\Solution@Emphasis#1\if@shadedsolutions%
{\cellcolor{SolutionColor}}%
\else%
\fi\endgroup\else\phantom{#1}\fi}%
\makeatother%

\begin{questions}
\question[1] Fill in the missing cell of this table:\par

\begin{tabular}{|l|l|c|c|}
\hline Mechanics     &Equation                                                          &Unit\\
\hline Distance      &\solutiontable{$x=x_{0}+v_{0}t+\dfrac{1}{2}at^{2}$}                &m\\  
\hline Weight        &$w=m\cdot g $                                                     &kg\\ 
\hline Kinetic energy&$K=\dfrac{1}{2}mv^{2}$                                            &J\\ 
\hline%
\end{tabular}%

\end{questions}

\end{document}

Blockquote

enter image description here

  • Hi Roger, is it possible to unframe solutions in the table, but frame solutions everywhere else in the document? – Mathemanic Jul 5 at 5:30

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.