I am trying to use the table environment inside the solution
environment of the exam
documentclass. Unfortunately this doesnt work as stated in this question since table
is also a float.
The solution environment internally uses a \vbox and this has as a consequence that floats are not allowed inside this environment. Instead of using the floating environment table you can use a center environment
Since they work outside of the solution
environment i am looking for a way to modify \begin{table} ... \end{table}
to act as it is outside the solution and inside replaces itself with \begin{center}...\end{center}
.
Fortunately as this post shows its easy to find out whether or not you are inside a solution
environment. I tested this and it works.
However since the documents i have to adapt to the exam
documentclass are numerous and are also used in other documentclasses I would ideally not create a new environment but adapt the table
environments similar to what happend here to the figure
or here to tabular environment. This is my code so far:
UPDATE: I dont know why, but with \center
instead of \begin{center}
the error is gone and also allows a way to tread the optional argument of table
\documentclass{exam}
\let\oldtable\table
\let\endoldtable\endtable
\renewenvironment{table}[1][h]
{\ifinner \center \else \oldtable[#1] \fi}
{\ifinner \endcenter \else \endoldtable \fi}
\begin{document}
\begin{questions} %error is no \question
\printanswers
\question{Question featuring a table environment}
\begin{table}[h]
\begin{tabular}{|ll|}
Question & in \\
Question & part \\
\end{tabular}
\end{table}
\begin{solution}
Solution featuring a table environment
\begin{table}[h]
\begin{tabular}{|ll|}
Solution & in \\
Solution & part \\
\end{tabular}
\end{table}
\end{solution}
\end{questions}
\end{document}
But I fear I am not handling the paramter of table
correct, since this leads to the error: Unknown float option `['. \begin{table}[
This solution works outside "inner" and can handle the optional argument of table
, however if \ifinner
is true i get the error
Extra }, or forgotten \endgroup. \end{table}
Does anyone has a suggestion on how to adapt table
based on the environment?
Thank you very much
\caption
, you can use thecenter
environment. If you need a caption, use\captionof{table}{some caption}
.table
parts in themfloat
package), which can easily be done with Search and Replace in your editor.