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
and the \captionof
command (from the caption
package) to provide the caption (now the tabular material won't float, of course):
\documentclass[answers]{exam}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\begin{document}
\begin{questions}
\question Test.
\begin{solution}
Voici le tableau demandé:
\begin{center}
\captionof{table}{Répartition des collèges publics du Québec selon la langue d'enseignement}
\label{langue2}
\begin{tabular}{|c|c|c|}
\hline
Langue d'enseignement & Effectifs & Fréquences\\
\hline
Français & $41$ &$ 0.854$\\
\hline
Anglais & $ 5$ &$ 0.104$\\
\hline
Bilingue & $ 2$ &$ 0.042$\\
\hline
\end{tabular}
\end{center}
\end{solution}
\end{questions}
\end{document}
Not directly related to the issue of the question, but you might be interested in the booktabs
package to design your tables (vertical rules won't be allowed, but this is an advantage in most cases). Here's the previous code, using booktabs
:
\documentclass[answers]{exam}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{caption}
\begin{document}
\begin{questions}
\question Test.
\begin{solution}
Voici le tableau demandé:
\begin{center}
\captionof{table}{Répartition des collèges publics du Québec selon la langue d'enseignement}
\label{langue2}
\begin{tabular}{@{}ccc@{}}
\toprule
Langue d'enseignement & Effectifs & Fréquences\\
\cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(l){3-3}
Français & $41$ &$ 0.854$\\
Anglais & $ 5$ &$ 0.104$\\
Bilingue & $ 2$ &$ 0.042$\\
\bottomrule
\end{tabular}
\end{center}
\end{solution}
\end{questions}
\end{document}
A new request has been made in a comment: if \SolutionEmphasis
has been used to change the solutions formatting, \captionsetup
can be used so that the formatting for the caption used inside a solution
environment matches the one of the solutions; a little example in which \SolutionEmphasis{\color{blue}}
is used:
\documentclass[answers]{exam}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{caption}
\DeclareCaptionFont{blue}{\color{blue}}
\SolutionEmphasis{\color{blue}}
\begin{document}
\begin{questions}
\question Test.
\begin{solution}
Voici le tableau demandé:
\begin{center}
\captionsetup{font=blue}
\captionof{table}{Répartition des collèges publics du Québec selon la langue d'enseignement}
\label{langue2}
\begin{tabular}{@{}ccc@{}}
\toprule
Langue d'enseignement & Effectifs & Fréquences\\
\cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(l){3-3}
Français & $41$ &$ 0.854$\\
Anglais & $ 5$ &$ 0.104$\\
Bilingue & $ 2$ &$ 0.042$\\
\bottomrule
\end{tabular}
\end{center}
\end{solution}
\end{questions}
\end{document}
Instead of font=blue
in the above code, one can use labelfont=blue
to change only the color for the caption label, or textcolor=blue
to change only the color for the caption text.
\caption
statements: one of them is redundant, right? It would also be helpful if you converted your code into a Minimum (non)Working Example (MWE).solution
environment (Voir Tableau~\ref{langue2}
) so that it's allowed to float. I don't think that, if the table is not floating, a caption is necessary.