tabularx 中未定义的控制序列

tabularx 中未定义的控制序列

我想在我的 Latex 文件中添加一个表格,其中的文本显示在两列上,但我收到以下错误:

Undefined control sequence. <inserted text> {@{}lYYYYYY@{}} \toprule &\multicolumn {2}{c}{\bfseries Sour... l.221 \end{tabularx}

下表为:

\begin{table}
\caption{caption).}\label{table:mr}
\begin{tabularx}{\textwidth}{@{}lYYYYYY@{}}
\toprule
&\multicolumn{2}{c}{\bfseries Source}
&\multicolumn{2}{c}{\bfseries Target}
&\multicolumn{2}{c}{\bfseries Target with GANs} \\
\cmidrule(lr){2-3} \cmidrule(l){4-5} \cmidrule(l){6-7}  
&Frames 
&Score 
&Frames 
&Score
&Frames
&Score
\\
\midrule
A Constant Rectangle & 43M & 302 & 122 & 0 & \textbf{260K} & \textbf{362} \\
A Moving Square & 43M & 302 & 100 & 0 & \textbf{384K} & \textbf{300} \\
Green Lines & 43M & 302 & 186 & 2 & \textbf{288K} & \textbf{300} \\
Diagonals & 43M & 302 & 100 & 0 & \textbf{383K} & \textbf{330} \\
\bottomrule
\end{tabularx}
\end{table}

此表格在另一份只有一列的文档中有效。如果问题出在表格大小上,那么我不介意它扩展到两列,但不幸的是,添加 * 也不起作用。

答案1

 \usepackage{booktabs}

\toprule缺失。et al需要它

答案2

  • 您的表格代码很好(但结果看起来不太漂亮)。
  • 你在序言中写了什么(和遗漏了什么),我们不知道,因为你没有提供 mwe(最小工作示例),一个完整的小文档,其中包含必要的序言和你的表格(然而赫伯特从你的错误中找到它)
  • 无关,看看您是否会喜欢以下重新设计的表格:

    \documentclass{article}
    \usepackage{booktabs, makecell, tabularx}
    \renewcommand\theadfont{\bfseries}
    \renewcommand\theadgape{}
    \newcolumntype{Y}{>{\centering\arraybackslash}X}
    
    \usepackage{lipsum}
    
    \begin{document}
    \lipsum[11]
    \begin{table}[htb]
    \caption{caption).}\label{table:mr}
    \begin{tabularx}{\textwidth}{@{}l *{6}{Y} @{}}
    \toprule
    &\multicolumn{2}{c}{\thead{Source}}
    &\multicolumn{2}{c}{\thead{Target}}
    &\multicolumn{2}{c}{\thead{Target\\ with GANs}} \\
    \cmidrule(r){2-3} \cmidrule(r){4-5} \cmidrule{6-7}
    &Frames
    &Score
    &Frames
    &Score
    &Frames
    &Score
    \\
    \midrule
    A Constant Rectangle & 43M & 302 & 122 & 0 & \textbf{260K} & \textbf{362} \\
    A Moving Square & 43M & 302 & 100 & 0 & \textbf{384K} & \textbf{300} \\
    Green Lines & 43M & 302 & 186 & 2 & \textbf{288K} & \textbf{300} \\
    Diagonals & 43M & 302 & 100 & 0 & \textbf{383K} & \textbf{330} \\
    \bottomrule
    \end{tabularx}
    \end{table}
    \lipsum
    \end{document}
    

这使

在此处输入图片描述

  • 从您问题中的文字可以得出结论,您有两列文档。在这种情况下,您的表格由于其宽度必须分布在两列上,即figure您应该使用figure*

相关内容