LaTeX/Overleaf表格Multirow报错:未定义控制序列问题咨询
问题描述
用户提供的LaTeX代码在Overleaf中能正常输出表格,但提示“Undefined control sequence.”错误,对应\multirow相关代码行被标红。代码如下:
\documentclass[a4paper,oneside,11pt]{report} \documentclass{standalone} \usepackage{standalone} \usepackage{multirow} \usepackage{multicol} \begin{document} \begin{table}[h!] \begin{center} \caption{Algorithm Performance Evaluation Utilizing Different Features with 10-fold CV} \label{tab:table2} \begin{tabular}{|c|c|c|c|c|} \hline \multicolumn{2}{|cc|}{} & \multicolumn{3}{c|}{\textbf{Feature Sets}}\\ \hline \textbf{Classifiers } & \textbf{Evaluation Metrics} & \textbf{TF-IDF} & \textbf{Unigram + Bigram} & \textbf{Bag of words}\\ \hline & Accuracy & 0.540 & 0.672 & 0.528\\ \cline{2-5} \multirow{Na\"{\i}ve Bayes} & Precision & 0.755 & 0.750 & 0.747\\ \cline{2-5} & Recall & 0.188 & 0.565 & 0.157\\ \cline{2-5} & F1 score & 0.300 & 0.644 & 0.258\\ \hline & Accuracy & 0.687 & 0.728 & 0.686\\ \cline{2-5} \multirow{SVM} & Precision & 0.692 & 0.769 & 0.719\\ \cline{2-5} & Recall & 0.732 & 0.694 & 0.665\\ \cline{2-5} & F1 score & 0.711 & 0.729 & 0.690\\ \hline & Accuracy & 0.689 & 0.684 & 0.686\\ \cline{2-5} \multirow{Random Forest} & Precision & 0.728 & 0.747 & 0.737\\ \cline{2-5} & Recall & 0.655 & 0.609 & 0.629\\ \cline{2-5} & F1 score & 0.689 & 0.669 & 0.678\\ \hline & Accuracy & 0.646 & 0.660 & 0.654\\ \cline{2-5} \multirow{Decision Tree} & Precision & 0.675 & 0.700 & 0.686\\ \cline{2-5} & Recall & 0.635 & 0.622 & 0.635\\ \cline{2-5} & F1 score & 0.654 & 0.659 & 0.659\\ \hline & Accuracy & 0.639 & 0.644 & 0.645\\ \cline{2-5} \multirow{Adaboost} & Precision & 0.641 & 0.664 & 0.664\\ \cline{2-5} & Recall & 0.741 & 0.658 & 0.661\\ \cline{2-5} & F1 score & 0.683 & 0.661 & 0.662\\ \hline & Accuracy & 0.684 & 0.686 & 0.681\\ \cline{2-5} \multirow{Gradient Boosting} & Precision & 0.696 & 0.702 & 0.706\\ \cline{2-5} & Recall & 0.718 & 0.690 & 0.679\\ \cline{2-5} & F1 score & 0.706 & 0.698 & 0.688\\ \hline \end{tabular}\\ \end{center} \end{table} \end{document}
错误原因
- 重复声明文档类:LaTeX只允许存在一个
\documentclass命令,你同时声明了report和standalone,后者会覆盖前者,且standalone类不适合生成包含表格、标题的完整文档结构。 \multirow命令语法错误:\multirow的正确用法是\multirow{行数}{宽度}{内容},你直接将分类器名称作为第一个参数传入,导致LaTeX无法识别这个非法语法,触发“Undefined control sequence”错误。- 表格格式小问题:
\multicolumn{2}{|cc|}{}的列格式写错,应该用|c|保证单元格对齐;表格末尾多余的\\会产生不必要的空白。
修复后的代码
\documentclass[a4paper,oneside,11pt]{report} \usepackage{multirow} \usepackage{multicol} \begin{document} \begin{table}[h!] \begin{center} \caption{Algorithm Performance Evaluation Utilizing Different Features with 10-fold CV} \label{tab:table2} \begin{tabular}{|c|c|c|c|c|} \hline \multicolumn{2}{|c|}{} & \multicolumn{3}{c|}{\textbf{Feature Sets}}\\ \hline \textbf{Classifiers } & \textbf{Evaluation Metrics} & \textbf{TF-IDF} & \textbf{Unigram + Bigram} & \textbf{Bag of words}\\ \hline \multirow{4}{*}{Na\"{\i}ve Bayes} & Accuracy & 0.540 & 0.672 & 0.528\\ \cline{2-5} & Precision & 0.755 & 0.750 & 0.747\\ \cline{2-5} & Recall & 0.188 & 0.565 & 0.157\\ \cline{2-5} & F1 score & 0.300 & 0.644 & 0.258\\ \hline \multirow{4}{*}{SVM} & Accuracy & 0.687 & 0.728 & 0.686\\ \cline{2-5} & Precision & 0.692 & 0.769 & 0.719\\ \cline{2-5} & Recall & 0.732 & 0.694 & 0.665\\ \cline{2-5} & F1 score & 0.711 & 0.729 & 0.690\\ \hline \multirow{4}{*}{Random Forest} & Accuracy & 0.689 & 0.684 & 0.686\\ \cline{2-5} & Precision & 0.728 & 0.747 & 0.737\\ \cline{2-5} & Recall & 0.655 & 0.609 & 0.629\\ \cline{2-5} & F1 score & 0.689 & 0.669 & 0.678\\ \hline \multirow{4}{*}{Decision Tree} & Accuracy & 0.646 & 0.660 & 0.654\\ \cline{2-5} & Precision & 0.675 & 0.700 & 0.686\\ \cline{2-5} & Recall & 0.635 & 0.622 & 0.635\\ \cline{2-5} & F1 score & 0.654 & 0.659 & 0.659\\ \hline \multirow{4}{*}{Adaboost} & Accuracy & 0.639 & 0.644 & 0.645\\ \cline{2-5} & Precision & 0.641 & 0.664 & 0.664\\ \cline{2-5} & Recall & 0.741 & 0.658 & 0.661\\ \cline{2-5} & F1 score & 0.683 & 0.661 & 0.662\\ \hline \multirow{4}{*}{Gradient Boosting} & Accuracy & 0.684 & 0.686 & 0.681\\ \cline{2-5} & Precision & 0.696 & 0.702 & 0.706\\ \cline{2-5} & Recall & 0.718 & 0.690 & 0.679\\ \cline{2-5} & F1 score & 0.706 & 0.698 & 0.688\\ \hline \end{tabular} \end{center} \end{table} \end{document}
关键修复点说明
- 删除了重复的
\documentclass{standalone}和\usepackage{standalone},保留适合生成完整文档的report类。 - 修正所有
\multirow的用法:每个分类器对应4行评估指标,因此使用\multirow{4}{*}{分类器名称},其中4是跨行数,*表示自动匹配列宽。 - 修正了
\multicolumn{2}{|cc|}{}为\multicolumn{2}{|c|}{},保证表格单元格对齐。 - 移除了表格末尾多余的
\\,避免不必要的空白。
内容的提问来源于stack exchange,提问作者Shimanto
相关产品推荐
相关产品推荐

