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.
The floating capabilities of wrapfig
and relatives are restricted; in particular, placement near a page break is problematic. The wrapfig
documentation mentions these facts:
The ability to float is somewhat restricted, and you will get best
results by giving exact manual placement, but floating is more
convenient while revising the document. Any changes to the formatting
can ruin your manual positioning so you should adjust the placement
just before printing a final copy. Here are some tips for good
placement:
• The environment should be placed so as to not run over a page
break...
Best Answer
You can use an existing float such as
figure
instead ofminipage
to hold your side by side figure and table.Note however that while this works, LaTeX sees this as a figure while floating boxes around so only keeps it in sequence with figures this means that if some tables are on their own in a table environment they may float out of sequence with tables that are in a figure environment.
The end result is that the list of tables looks like
The simplest fix is to uncomment the commented line so that figures and tables are kept in the same sequence. This has the disadvantage that LaTeX won't then float any figure past any table so it gives less flexibility in the algorithm but it has the advantage of working and placing teh floats in the correct order as shown in the lists: