# printanswer in table in exam class

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}
\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}


• 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

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
,twoside
]{exam}
\usepackage{booktabs}

\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
\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
• 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

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 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
\begin{document}

\makeatletter%
{\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

• 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