[Tex/LaTex] Using “moderncv” package, the \cvitemwithcomment command gives error

floatsmoderncvtables

I'm trying to create my personal CV using moderncv package but I'm getting an error: in language skills section I'd like to insert a table resuming my skills using the code as follows

\section{Languages}
\cvitemwithcomment{Italian}{Mother tongue}{}
\cvitemwithcomment{English}{\begin{table}
        \centering
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            \multicolumn{2}{|c|}{Understanding} & \multicolumn{2}{c|}{Speaking}          & Writing \\ \hline
            Listening         & Reading        & Spoken interaction & Spoken production & -       \\ \hline
            C1                & C1              & C1                 & B2                & B2      \\ \hline
        \end{tabular}
    \end{table}}{}
\cvitemwithcomment{Spanish}{\begin{table}
        \centering
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            \multicolumn{2}{|c|}{Understanding} & \multicolumn{2}{c|}{Speaking}          & Writing \\ \hline
            Listening         & Reading        & Spoken interaction & Spoken production & -       \\ \hline
            B2                & B2              & B1                 & B1                & B1      \\ \hline
        \end{tabular}
    \end{table}}{}

However, while compiling I get these repeated errors:

Environment table undefined. \end{table}}{} 
\begin{document} ended by \end{table}. \end{table}}{} 
\begin{minipage} on input line 131 ended by \end{table}. \end{table}}{}

and compilation is blocked.
Could someone give me some hint to solve this problem?

Best Answer

Don't use float environments, such as table or figure, in moderncv; since it makes no sense to have floating objects in a CV, they are not implemented by the class: notice also that the length \tabcolsep is not set by the class, so it has 0pt as value; you need to change it using something like

\setlength\tabcolsep{6pt}

otherwise, there will be no separation between columns in tabular material. Your code with those recommendations:

\documentclass{moderncv}
\moderncvtheme{classic}

\firstname{John}
\lastname{Doe}

\setlength\tabcolsep{6pt}

\begin{document}

\makecvtitle

\section{Languages}
aaaa
\cvitemwithcomment{Italian}{Mother tongue}{}
\cvitemwithcomment{English}{%
        \centering
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            \multicolumn{2}{|c|}{Understanding} & \multicolumn{2}{c|}{Speaking}          & Writing \\ \hline
            Listening         & Reading        & Spoken interaction & Spoken production & -       \\ \hline
            C1                & C1              & C1                 & B2                & B2      \\ \hline
        \end{tabular}%
    }{}
\cvitemwithcomment{Spanish}{%
        \centering
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            \multicolumn{2}{|c|}{Understanding} & \multicolumn{2}{c|}{Speaking}          & Writing \\ \hline
            Listening         & Reading        & Spoken interaction & Spoken production & -       \\ \hline
            B2                & B2              & B1                 & B1                & B1      \\ \hline
        \end{tabular}%
    }{}

\end{document}

As a side note, your tables have too many lines. Here I changed the tables slightly and used the features provided by the booktabs package:

\documentclass{moderncv}
\moderncvtheme{classic}
\usepackage{booktabs}

\firstname{John}
\lastname{Doe}

\setlength\tabcolsep{6pt}

\begin{document}

\makecvtitle

\section{Languages}
\cvitemwithcomment{Italian}{Mother tongue}{}
\cvitemwithcomment{English}{%
        \centering
        \begin{tabular}{*{5}{c}}
            \toprule
            \multicolumn{2}{c}{Understanding} & \multicolumn{2}{c}{Speaking}          & Writing \\ \midrule
            & & Spoken & Spoken & \\
            Listening         & Reading        &  interaction &  production & -       \\             C1                & C1              & C1                 & B2                & B2      \\ \bottomrule
        \end{tabular}%
    }{}
\cvitemwithcomment{Spanish}{%
        \centering
        \begin{tabular}{*{5}{c}}
            \toprule
            \multicolumn{2}{c}{Understanding} & \multicolumn{2}{c}{Speaking}          & Writing \\ \midrule
            & & Spoken & Spoken & \\
            Listening         & Reading        & interaction & production & -       \\ \hline
            B2                & B2              & B1                 & B1                & B1      \\ \bottomrule
        \end{tabular}%
    }{}

\end{document}

enter image description here