如何在两列文档中创建全宽表格而不出现以下错误?这是我的代码
\documentclass{article}
\usepackage{spconf,amsmath,graphicx}
\usepackage{graphicx,subcaption}
\usepackage{lipsum}
\usepackage{subfig}
\usepackage{sidecap}
\usepackage{amsmath,graphicx,cite}
\usepackage{amssymb}
\usepackage{booktabs}
\newcommand{\centerbox}[1]{\raisebox{1ex}{\raisebox{-0.5\height}{#1}}}
\def\x{{\mathbf x}}
\def\L{{\cal L}}
\begin{document}
\section{1}
\begin {table*}
\begin{tabular*}{\textwidth}{@{\extracolsep{\stretch{1}}}*{7}{r}@{}}
\toprule
M & TA & MO & P & N & ID & CC & XC & KL \\
\hline
method & 0.79 & 0.59 & - & - & 4& 3 & 5\\
ED [] & 5 & 7 & - & -& 6 \\
CR & 4 & 7&- & - & 22 \\
NB[]& 2 & 75 & - & - & 6\\
\hline
\end{tabular*}
\caption{Set of observations }
\end{table*}
\end{document}
答案1
从代码中我成功提取了以下MWE:
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\section{section}
\begin {table}[htb]
\begin{tabular*}{\textwidth}{@{\hskip 6pt\extracolsep{\stretch{1}}}*{9}{r}}
\toprule
M & TA & MO & P & N & ID & CC & XC & KL \\
\midrule
method & 0.79 & 0.59 & - & - & 4 & 3 & 5 & \\
ED [] & 5 & 7 & - & - & 6 & & & \\
CR & 4 & 7 & - & - & 22 & & & \\
NB[] & 2 & 75 & - & - & 6 & & & \\
\bottomrule
\end{tabular*}
\caption{Set of observations }
\end{table}
\end{document}
这使:
我现在很好奇:你的问题是什么?
对于上图,我删除了所有不相关的软件包,并更正了表格中的列数,并在所有缺少的行中补充了“&”符号(实际上是除第一行之外的所有行)。这是问题吗?
附录:
在与 Christian Hupfer 交换了意见后,关于如何设置上面的表格,我(为了我的练习)又提出了两个解决方案。两者都添加到第一个解决方案中,以便您可以更轻松地比较它们的代码和结果。我为它们添加了两个包:tabularx
和siunitx
:
\documentclass{article}
\usepackage{booktabs,tabularx}
\usepackage{siunitx}
\newcommand\mcx{\multicolumn{1}{>{\centering\arraybackslash}X}}
\begin{document}
\section{section}
\begin {table}[htb]
\begin{tabular*}{\textwidth}{@{\hskip 6pt\extracolsep{\stretch{1}}}*{9}{r}}
\toprule
M & TA & MO & P & N & ID & CC & XC & KL \\
\midrule
method & 0.79 & 0.59 & - & - & 4 & 3 & 5 & \\
ED [] & 5 & 7 & - & - & 6 & & & \\
CR & 4 & 7 & - & - & 22 & & & \\
NB[] & 2 & 75 & - & - & 6 & & & \\
\bottomrule
\end{tabular*}
\caption{Set of observations }
\end{table}
Similarly result can be obtained with \verb+tabularx+ packages
\begin {table}[htb]
\begin{tabularx}{\textwidth}{*{9}{>{\raggedleft\arraybackslash}X}}
\toprule
M & TA & MO & P & N & ID & CC & XC & KL \\
\midrule
method & 0.79 & 0.59 & {--} & {--} & 4 & 3 & 5 & \\
ED [] & 5 & 7 & {--} & {--} & 6 & & & \\
CR & 4 & 7 & {--} & {--} & 22 & & & \\
NB[] & 2 & 75 & {--} & {--} & 6 & & & \\
\bottomrule
\end{tabularx}
\caption{Set of observations}
\end{table}
One more solution with quite sophisticated table setting with exploiting packages \verb+tabularx+ and \verb+siunitx+:
\begin {table}[htb]
\begin{tabularx}{\textwidth}{r*{8}{S[table-format=2.2]}}
\toprule
\mcx{M} & \mcx{TA} & \mcx{MO} & \mcx{P} & \mcx{N} & \mcx{ID} & \mcx{CC} & \mcx{XC} & \mcx{KL} \\
\midrule
method & 0.79 & 0.59 & {--} & {--} & 4 & 3 & 5 & \\
ED [] & 5 & 7 & {--} & {--} & 6 & & & \\
CR & 4 & 7 & {--} & {--} & 22 & & & \\
NB[] & 2 & 75 & {--} & {--} & 6 & & & \\
\bottomrule
\end{tabularx}
\caption{Set of observations}
\end{table}
\end{document}