如何在表格中间插入一行

如何在表格中间插入一行

我有一个多列表格。我在下面分享代码。我想在这个表的中间放一条线。这条线应该经过第 4 列(第一My-Pipe列)。我做不到。有办法吗?

\documentclass{article}
\usepackage{booktabs,caption,siunitx}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}
\begin{table}
\setlength\tabcolsep{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
    *{2}{l*{3}{S[table-format=2.2]}}}
\cmidrule{1-4} \cmidrule{5-8} % instead of \toprule
\textbf{col1} & \mc{\textbf{MymcNet}} & \mc{\textbf{Bazilat}} 
   & \mc{\textbf{My-Pipe}} &
\textbf{col1} & \mc{\textbf{MymcNet}} & \mc{\textbf{Bazilat}} 
   & \mc{\textbf{My-Pipe}} \\
& & \mc{\textbf{et al}} & & & & \mc{\textbf{et al}}\\
\cmidrule{1-4} \cmidrule{5-8} 
aa &     &   &    & ac &     &   &    \\
ab &     &   &    & dd &     &   &    \\
bb &     &   &    & de &     &   &    \\
cb &     &   &    & df &     &   &    \\
\cmidrule{1-4} \cmidrule{5-8} % instead of \bottomrule
\end{tabular*}
\captionsetup{skip=0.333\baselineskip}
\caption{Test set scores.}
\end{table}
\end{document}

最后,我该怎么做才能获得下面的任何图像?

在此处输入图片描述

编辑

我决定使用@Zarko 的建议。当我复制并粘贴共享代码时,它完美地工作了。但是,我的原始表格每侧还有 2 列,因此我尝试相应地更新解决方案。但是,每当我尝试时,我都会收到下面共享的错误。此外,我在 beamer 框架中使用这个表。据我所知,当行数超过 10 时,它不适合框架。有办法修复它吗?我有 13 行,如我在编辑的表格中所示。

./demo.vrb:24: 放错 \noalign。\cmidrule ->\noalign {\ifnum 0=`}\fi \@ifnextchar [{\@cmidrule }{\@cmidrule ... l.24 cmidrule(r){1-6} \cmidrule (l){7-12}

我修改后的代码如下:

\begin{frame}[fragile]{example}
  \begin{table}
\sisetup{table-format=2.2}
\setlength\aboverulesep{0pt}
\setlength\belowrulesep{0pt}
\setlength\tabcolsep{3pt}
\renewcommand\arraystretch{1.2}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
                             l
                        *{5}{S}
                             |
                             l
                        *{5}{S}
                            @{}}
    \cmidrule(r){1-6} \cmidrule(l){7-12}
\textbf{col1}   & {\thead{MymcNet}} & {\thead{Bazilat\\ et all}} & {\thead{My-Pipe}} & {\thead{nextop1}} & {\thead{nextop2}}
                &
\textbf{col1}   & {\thead{MymcNet}} & {\thead{Bazilat\\ et all}} & {\thead{My-Pipe}} & {\thead{nextop1}} & {\thead{nextop2}}   \\
    \cmidrule(r){1-6} \cmidrule(l){7-12}
aa  &   &   &  & &    & ac    &   &   &   & & \\
ab  &   &   &  & &    & dd    &   &   &   & & \\
bb  &   &   &  & &    & de    &   &   &   & & \\
cb  &   &   &  & &    & df    &   &   &   & & \\
aa  &   &   &  & &    & ac    &   &   &   & & \\
ab  &   &   &  & &    & dd    &   &   &   & & \\
bb  &   &   &  & &    & de    &   &   &   & & \\
cb  &   &   &  & &    & df    &   &   &   & & \\
aa  &   &   &  & &    & ac    &   &   &   & & \\
ab  &   &   &  & &    & dd    &   &   &   & & \\
bb  &   &   &  & &    & de    &   &   &   & & \\
cb  &   &   &  & &    & df    &   &   &   & & \\
cb  &   &   &  & &    & df    &   &   &   & & \\

cmidrule(r){1-6} \cmidrule(l){7-12}
\end{tabular*}
\caption{Test set scores.}
    \end{table}
\end{frame}

編輯-2 最后我终于摆脱了上面提到的错误。不幸的是,我无法再将表格放入框架中(尽管我听从了@Zarko 的建议。最终代码如下:

\documentclass[10pt,table]{beamer}
\usetheme[progressbar=frametitle]{metropolis}
\begin{frame}[fragile]{foo}
  \begin{table}
        \small
        \setlength\tabcolsep{0pt}
        \captionsetup{skip=0.333\baselineskip}
        \caption{Statistics.}
        \setlength\tabcolsep{3pt}
        \begin{tabular*}{\textwidth}{@{}
                                     l
                                *{5}{S}
                                     |
                                     l
                                *{5}{S}
                                    @{}}
            \cmidrule(r){1-6} \cmidrule(l){7-12}
        \textbf{col1}   & \mc{\textbf{mymcNet}} & \mc{\textbf{Bazilat}} & \mc{\textbf{My-Pipe}} & \mc{\textbf{|e1|}} & {\thead{|e2|}}
                        &
        \textbf{col1}   & \mc{\textbf{mymcNet}} & \mc{\textbf{Bazilat}} & \mc{\textbf{My-Pipe}} & \mc{\textbf{|e1|}} & {\thead{|e2|}} \\
        %& & \mc{\textbf{et al}} & & & & \mc{\textbf{et al}}\\
        \cmidrule{1-6} \cmidrule{7-12} 
        aa & 230796  & 31372  & 29060  & 363  & 36  & 
        ab & 211820  & 11158  & 10468  & 380  & 47 \\ 
        ac & 417750  & 56515  & 57929  & 269  & 55  &
        ad & 384554  & 37349  & 12069  & 404  & 46  \\ 
        bb & 1174261 & 159437 & 174068 & 2776 & 112 &
        cc & 124336  & 16089  & 15724  & 439  & 45 \\
        dd & 204585  & 25148  & 25096  & 121  & 35  & 
        ff & 112530  & 14063  & 14077  & 1140 & 62  \\ 
        gg & 169283  & 14533  & 13228  & 1129 & 52  & 
        rr & 75964   & 11877  & 11548  & 750  & 39  \\
        uu & 22525   & 12103  & 12410  & 599  & 59   &
        yy & 281057  & 35217  & 35430  & 985  & 43  \\
        uu & 20166   & 11418  & 10448  & 716  & 73  & 
        mm & 148401  & 12344  & 13308  & 540  & 48  \\
        vv & 185113  & 17074  & 16324  & 462  & 59  & 
        zz & 63013   & 10332  & 10897  & 1047 & 56  \\
        kk & 359477  & 36101  & 10090  & 228  & 36  & 
        sd & 31212   & 10139  & 10422  & 355  & 43 \\ 
        gn & 38834   & 10226  & 10199  & 1116 & 67  & 
        rr & 162621  & 18290  & 21041  & 1810 & 89  \\ 
        qh & 80378   & 10332  & 10023  & 159  & 44  & 
        mj & 66645   & 9797   & 20377  & 211  & 40 \\
        vv & 277032  & 12193  & 10652  & 278  & 40  & 
        cz & 186467  & 11458  & 10051  & 335  & 65  \\
        fa & 80575   & 12440  & 13028  & 1294 & 61  & 
        lj & 98608   & 12663  & 12012  & 32   & 12  \\

        \cmidrule{1-6} \cmidrule{7-12} 
        \end{tabular*}
        \label{table-stat-ud}
        \end{table} 
\end{frame}
  \end{document}

你知道我该如何让它工作吗?当前视图如下:

在此处输入图片描述

答案1

像这样:

在此处输入图片描述

(红线表示文本边框)

\documentclass{article}
\usepackage{booktabs, makecell}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{}
\usepackage[skip=0.333\baselineskip]{caption}
\usepackage{siunitx}

\begin{document}
    \begin{table}
\sisetup{table-format=2.2}
\setlength\aboverulesep{0pt}
\setlength\belowrulesep{0pt}
\setlength\tabcolsep{3pt}
\renewcommand\arraystretch{1.2}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
                             l
                        *{3}{S}
                             |
                             l
                        *{3}{S}
                            @{}}
    \cmidrule(r){1-4} \cmidrule(l){5-8}
\textbf{col1}   & {\thead{MymcNet}} & {\thead{Bazilat\\ et all}} & {\thead{My-Pipe}}
                &
\textbf{col1}   & {\thead{MymcNet}} & {\thead{Bazilat\\ et all}} & {\thead{My-Pipe}}   \\
    \cmidrule(r){1-4} \cmidrule(l){5-8}
aa  &   &   &       & ac    &   &   &    \\
ab  &   &   &       & dd    &   &   &    \\
bb  &   &   &       & de    &   &   &    \\
cb  &   &   &       & df    &   &   &    \\
    \cmidrule(r){1-4} \cmidrule(l){5-8}
\end{tabular*}
\caption{Test set scores.}
    \end{table}
\end{document}

附录: 我必须承认,我迷失在你的子问题和缺乏基本信息中。所以这是我最后一次尝试改进我的答案。如果你需要进一步的帮助,请提出新问题,以便更多人可以看到它并最终帮助你。我很确定你的基本问题已经解决了:-)

\documentclass{beamer}
\usepackage{booktabs, makecell, rotating}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{}
\usepackage{siunitx}

\begin{document}
\begin{frame}
        \begin{table}
\caption{Statistics.}
\scriptsize
% in the case, that some settings below should be global, move them to preamble
\setlength\aboverulesep{0pt}
\setlength\belowrulesep{0pt}
\renewcommand\arraystretch{1.2}
%
\sisetup{group-digits}
\setlength\tabcolsep{3pt}
\settowidth\rotheadsize{\theadfont mymcNet}
    \begin{tabular*}{\textwidth}{@{}
                                 l
    S[table-format=7]*{2}{S[table-format=6]}S[table-format=4]S[table-format=3]
                                 |
                                 l
    S[table-format=6]*{2}{S[table-format=5]}S[table-format=4]S[table-format=2]
                                 @{}}
        \cmidrule(r){1-6} \cmidrule(l){7-12}
    \rothead{col1}
        & {\rothead{mymcNet}} & {\rothead{Bazilat\\ et all}} & {\rothead{My-Pipe}} & {\rothead{e1}} & {\rothead{e2}}
        &
    \rothead{col1}
        & {\rothead{mymcNet}} & {\rothead{Bazilat\\ et all}} & {\rothead{My-Pipe}} & {\rothead{e1}} & {\rothead{e2}} \\
    \cmidrule(r){1-6} \cmidrule(l){7-12}
    aa & 230796  & 31372  & 29060  & 363  & 36  &
    ab & 211820  & 11158  & 10468  & 380  & 47 \\
    ac & 417750  & 56515  & 57929  & 269  & 55  &
    ad & 384554  & 37349  & 12069  & 404  & 46  \\
    bb & 1174261 & 159437 & 174068 & 2776 & 112 &
    cc & 124336  & 16089  & 15724  & 439  & 45 \\
    dd & 204585  & 25148  & 25096  & 121  & 35  &
    ff & 112530  & 14063  & 14077  & 1140 & 62  \\
    gg & 169283  & 14533  & 13228  & 1129 & 52  &
    rr & 75964   & 11877  & 11548  & 750  & 39  \\
    uu & 22525   & 12103  & 12410  & 599  & 59   &
    yy & 281057  & 35217  & 35430  & 985  & 43  \\
    uu & 20166   & 11418  & 10448  & 716  & 73  &
    mm & 148401  & 12344  & 13308  & 540  & 48  \\
    vv & 185113  & 17074  & 16324  & 462  & 59  &
    zz & 63013   & 10332  & 10897  & 1047 & 56  \\
    kk & 359477  & 36101  & 10090  & 228  & 36  &
    sd & 31212   & 10139  & 10422  & 355  & 43 \\
    gn & 38834   & 10226  & 10199  & 1116 & 67  &
    rr & 162621  & 18290  & 21041  & 1810 & 89  \\
    qh & 80378   & 10332  & 10023  & 159  & 44  &
    mj & 66645   & 9797   & 20377  & 211  & 40 \\
    vv & 277032  & 12193  & 10652  & 278  & 40  &
    cz & 186467  & 11458  & 10051  & 335  & 65  \\
    fa & 80575   & 12440  & 13028  & 1294 & 61  &
    lj & 98608   & 12663  & 12012  & 32   & 12  \\
    \cmidrule(r){1-6} \cmidrule(l){7-12}
    \end{tabular*}
    \label{table-stat-ud}
        \end{table}
\end{frame}
\end{document}

在此处输入图片描述

答案2

那么,基于以下情况,情况如何tabularx

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage[table, svgnames]{xcolor}
\usepackage{booktabs,caption,siunitx, tabularx, makecell}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\newcommand{\mycmidrules}{\cmidrule(r{10pt}){1-4} \cmidrule(l{2pt}){5-8}}

\begin{document}

\begin{table}
\sisetup{table-format =2.2, table-column-width=1.8cm}%
\setlength{\tabcolsep}{4pt}
\renewcommand{\theadfont}{\normalsize\bfseries}
\renewcommand{\theadset}{\renewcommand{\arraystretch}{0.6}}
\let\cmidrulewidth\heavyrulewidth
\begin{tabularx}{\textwidth}{%
   X*{3}{S}!{\color{Gainsboro!60!Lavender}\vrule width 8pt}X*{3}{S}}
\mycmidrules% instead of \toprule
\thead[l]{col1} & {\thead{MymcNet}} & {\thead{Bazilat\\ et al}} & {\thead{My-Pipe}} &
\thead[l]{col1} &{\thead{MymcNet}} &{\thead{Bazilat\\et al}} &{\thead{My-Pipe}} \\
\arrayrulecolor{Gainsboro!60!Lavender}
\mycmidrules\arrayrulecolor{black}
aa & & & & ac & & & \\
ab & & & & dd & & & \\
bb & & & & de & & & \\
cb & & & & df & & & \\
\mycmidrules% instead of \bottomrule
\end{tabularx}
\captionsetup{skip=0.333\baselineskip}
\caption{Test set scores.}
\end{table}

\end{document} 

在此处输入图片描述

相关内容