Tabularx 中的计量单位(pt 插入)非法

Tabularx 中的计量单位(pt 插入)非法

我正在撰写一篇期刊论文,使用 Overleaf 网站来编写它。



\documentclass[runningheads]{llncs}
\usepackage{tabularx} 
\usepackage{multirow}



\begin{document}


\begin{table}[t]
\caption{tabmle1}
\label{tab2}
\begin{center}
\begin{tabularx}{\textwidth}{|X|X|X|X|}
\hline
\textbf{Dataset} &  \textbf{Metrics} & \textbf{algo1} & \textbf{algo2}  \\ \cline{1-4}
\multirow{4}{4} {data1} & M1 & 5.36778  & 6.20198 \\ \cline{2-4}
& M2 & 5.16952 & 3.78941     \\ \cline{2-4}

& M3 & 8.92139  & 9.63108  \\ \cline{2-4}

&M4 & 0.07484 & - 1.16580  \\ \cline{1-4}
%\hline
\multirow{4}{4}{data2} & M1& 2.02522 &  6.48972 \\ \cline{2-4}
& M2 & 6.15882 &    9.69980 \\ \cline{2-4}

& M3 & 8.12485  & 8.68411  \\ \cline{2-4}

& M4& -1.16187 & - 11.55713  \\ \cline{1-4}
%\hline
\end{tabularx} 
\end{center}
\end{table}
\end{document}

我收到此错误:

Illegal unit of measure (pt inserted).

<to be read again> 
                   \relax 
l.33 \end{tabularx}
                   
Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.

我是乳胶新手,我做了一些研究,表示此错误可能出现在换行符 \\ 后跟方括号的情况下,但此代码并非如此。其他建议使用Tabularx,它已经是使用过的环境。

此外,我真的不明白这个错误的根源。

提前感谢您的任何建议!

答案1

在此处输入图片描述

大部分内容都偏离主题,因为你的问题已经通过评论解决了。我会使用siunitx软件包来编写带有数字的列:

\documentclass[runningheads]{llncs}
\usepackage{multirow, tabularx}
\NewExpandableDocumentCommand\mcxbf{O{>{\centering\arraybackslash}X|}m}
     {\multicolumn{1}{#1}{\textbf{#2}}}
\usepackage{siunitx}


\begin{document}
    \begin{table}[ht]
\caption{Table 1}
\label{tab2}
    \centering
    \renewcommand\arraystretch{1.1}
\begin{tabularx}{\textwidth}{|X|X|S[table-format=-1.5]|S[table-format=-2.5]|}
    \hline
\mcxbf[|>{\centering\arraybackslash}X|]{Dataset} 
    & \mcxbf{Metrics} 
            & \mcxbf{algo1} 
                        & \mcxbf{algo2}  \\ 
    \hline
\multirow{4}{=}{data1} 
    & M1    & 5.36778   &  6.20198  \\ \cline{2-4}
    & M2    & 5.16952   &  3.78941  \\ \cline{2-4}
    & M3    & 8.92139   &  9.63108  \\ \cline{2-4}
    & M4    & 0.07484   & -1.16580  \\
\hline
\multirow{4}{=}{data2} 
    & M1    & 2.02522   &  6.48972  \\ \cline{2-4}
    & M2    & 6.15882   &  9.69980  \\ \cline{2-4}
    & M3    & 8.12485   &  8.68411  \\ \cline{2-4}
    & M4    & -1.16187  & -11.55713 \\ 
    \hline
\end{tabularx}
    \end{table}
\end{document}

附录: 您可能喜欢@{Mico 在下面的评论中建议的设计:

在此处输入图片描述

\documentclass[runningheads]{llncs}
\usepackage{booktabs, multirow, tabularx}
\NewExpandableDocumentCommand\mcxbf{O{>{\centering\arraybackslash}X}m}
     {\multicolumn{1}{#1}{\textbf{#2}}}
\NewExpandableDocumentCommand\mlxbf{O{>{\raggedright\arraybackslash}X}m}
     {\multicolumn{1}{#1}{\textbf{#2}}}
\usepackage{siunitx}


\begin{document}
    \begin{table}[ht]
\caption{Table 1}
\label{tab2}
    \centering
    \renewcommand\arraystretch{1.1}
\begin{tabularx}{\textwidth}{XX S[table-format=-1.5]S[table-format=-2.5]}
    \toprule
\mlxbf{Dataset} 
    & \mlxbf{Metrics} 
            & \mcxbf{algo1} 
                        & \mcxbf{algo2}  \\ 
    \midrule
\multirow{4}{=}{data1} 
    & M1    & 5.36778   &  6.20198  \\ 
    & M2    & 5.16952   &  3.78941  \\ 
    & M3    & 8.92139   &  9.63108  \\ 
    & M4    & 0.07484   & -1.16580  \\
    \midrule
\multirow{4}{=}{data2} 
    & M1    & 2.02522   &  6.48972  \\ 
    & M2    & 6.15882   &  9.69980  \\ 
    & M3    & 8.12485   &  8.68411  \\ 
    & M4    & -1.16187  & -11.55713 \\ 
    \bottomrule
\end{tabularx}
    \end{table}
\end{document}

相关内容