表格:\toprule 和 \midrule 内容重叠,\hline 上下需要留出空间

表格:\toprule 和 \midrule 内容重叠,\hline 上下需要留出空间

我的表格中出现以下问题:

  1. 顶部规则的内容与中部规则的内容重叠。

  2. 我需要在表格中间的水平线上方和下方留出一点空间。

代码如下:

\documentclass[10pt,journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{float}
\usepackage{multirow}
\usepackage{makecell}
\usepackage[caption=false,font=footnotesize]{subfig}
\usepackage{varwidth}
\graphicspath{ {./images/} }
\usepackage{nccmath}
\usepackage{afterpage}
\usepackage{placeins}
\usepackage{cuted}
\hyphenation{op-tical net-works semi-conduc-tor}
\bibliographystyle{IEEEtran}
\usepackage[figurename=Fig.]{caption}
\begin{document}

\begin{table}
        \begin{center}
            \caption{blah blah}
            \label{tab:table1}
            \begin{tabular}{cccccc}\toprule
                \multirow{2}{3em}{Training Size} & \multirow{2}{3em}{Test Size} & Classifier & Feature & \multirow{2}{3em}{Test Accuracy} & \multirow{2}{3em}{Training Time}\\
                \midrule
                35 & 15 & GBLinear & IEMG & 100 & 9.29\\ 
                35 & 15 & GBLinear & MAV & 100 & 8.89\\ 
                35 & 15 & GBLinear & MAV1 & 100 & 8.39\\ 
                35 & 15 & GBLinear & RMS & 100 & 5.32\\
                35 & 15 & Bagging SVM & MAV & 100 & 4.06\\
                35 & 15 & Bagging SVM & MAV1 & 100 & 2.9\\
                35 & 15 & Bagging SVM & RMS & 100 & 6.69\\\hline
                30 & 20 & GBLinear & IEMG & 98.75 & 8.23\\
                30 & 20 & GBLinear & MAV1 & 98.75 & 4.26\\
                30 & 20 & GBLinear & RMS & 98.75 & 8.31\\
                30 & 20 & Stacking SVM & MAV1 & 98.75 & 2.61\\\hline
                25 & 25 & GBLinear & IEMG & 98 & 8.08\\\hline
                20 & 30 & Bagging SVM & RMS & 98.33 & 4.3\\
                20 & 30 & GBLinear & IEMG & 98.33 & 6.13\\                
                 \bottomrule
            \end{tabular}
        \end{center}
    \end{table}

输出:

在此处输入图片描述

答案1

我猜您想在列标题(例如“测试大小”)中添加换行符。如果这个假设是正确的,您可能会对以下代码感兴趣,其中我使用了您已加载的包\thead中的makecell代码,而不是命令\multirow

我还用 替换了所有\hline命令,\midrule以改善间距。为了避免过多的垂直空白,我用 命令替换了环境center\centering为了确保表格不超过可用的行宽,我用 替换tabulartabular*添加了@{\extracolsep{\fill}}

在下面的 MWE 中,我还添加了表格的替代版本,其中水平线较少,并且带有包S中的类型列siunitx,以便将最后两列中的数字与小数点标记对齐。

在此处输入图片描述

\documentclass[10pt,journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{float}
\usepackage{multirow}
\usepackage{makecell}
\usepackage[caption=false,font=footnotesize]{subfig}
\usepackage{varwidth}
\graphicspath{ {./images/} }
\usepackage{nccmath}
\usepackage{afterpage}
\usepackage{placeins}
\usepackage{cuted}
\hyphenation{op-tical net-works semi-conduc-tor}
\bibliographystyle{IEEEtran}
\usepackage[figurename=Fig.]{caption}

\usepackage{siunitx}


\begin{document}

\begin{table}
    \centering
    \setlength{\tabcolsep}{0pt}
            \caption{blah blah}
            \label{tab:table1}
            \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}cccccc}\toprule
                \thead{Training\\ Size} & \thead{Test\\ Size} & \thead{Classifier} &\thead{Feature} & \thead{Test\\ Accuracy} & \thead{Training\\ Time}\\
                \midrule
                35 & 15 & GBLinear & IEMG & 100 & 9.29\\ 
                35 & 15 & GBLinear & MAV & 100 & 8.89\\ 
                35 & 15 & GBLinear & MAV1 & 100 & 8.39\\ 
                35 & 15 & GBLinear & RMS & 100 & 5.32\\
                35 & 15 & Bagging SVM & MAV & 100 & 4.06\\
                35 & 15 & Bagging SVM & MAV1 & 100 & 2.9\\
                35 & 15 & Bagging SVM & RMS & 100 & 6.69\\
                \midrule
                30 & 20 & GBLinear & IEMG & 98.75 & 8.23\\
                30 & 20 & GBLinear & MAV1 & 98.75 & 4.26\\
                30 & 20 & GBLinear & RMS & 98.75 & 8.31\\
                30 & 20 & Stacking SVM & MAV1 & 98.75 & 2.61\\
                \midrule
                25 & 25 & GBLinear & IEMG & 98 & 8.08\\
                \midrule
                20 & 30 & Bagging SVM & RMS & 98.33 & 4.3\\
                20 & 30 & GBLinear & IEMG & 98.33 & 6.13\\                
                 \bottomrule
            \end{tabular*}
\end{table}
    
\begin{table}
    \centering
    \setlength{\tabcolsep}{0pt}
            \caption{blah blah}
            \label{tab:table1}
            \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}ccllS[table-format=3.2]S[table-format=1.2]}\toprule
                \thead{Training\\ Size} & \thead{Test\\ Size} & \thead{Classifier} &\thead{Feature} & {\thead{Test\\ Accuracy}} & {\thead{Training\\ Time}}\\
                \midrule
                35 & 15 & GBLinear & IEMG & 100 & 9.29\\ 
                35 & 15 & GBLinear & MAV & 100 & 8.89\\ 
                35 & 15 & GBLinear & MAV1 & 100 & 8.39\\ 
                35 & 15 & GBLinear & RMS & 100 & 5.32\\
                35 & 15 & Bagging SVM & MAV & 100 & 4.06\\
                35 & 15 & Bagging SVM & MAV1 & 100 & 2.9\\
                35 & 15 & Bagging SVM & RMS & 100 & 6.69\\
                \addlinespace
                30 & 20 & GBLinear & IEMG & 98.75 & 8.23\\
                30 & 20 & GBLinear & MAV1 & 98.75 & 4.26\\
                30 & 20 & GBLinear & RMS & 98.75 & 8.31\\
                30 & 20 & Stacking SVM & MAV1 & 98.75 & 2.61\\
                \addlinespace
                25 & 25 & GBLinear & IEMG & 98 & 8.08\\
                \addlinespace
                20 & 30 & Bagging SVM & RMS & 98.33 & 4.3\\
                20 & 30 & GBLinear & IEMG & 98.33 & 6.13\\                
                 \bottomrule
            \end{tabular*}
\end{table}
 
\end{document}

答案2

请参阅评论以了解问题的解决方案。我添加了&&&&& \\免费空间。

在此处输入图片描述

\documentclass[varwidth=\maxdimen]{standalone}

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{makecell}

\begin{document}
    
    \begin{table}
        
        \caption{blah blah}
        \label{tab:table1}
        \begin{tabular}{cccccc}
            \toprule
            \makecell[c]{Training \\ Size} & \makecell[c]{Test \\ Size} & \makecell[c]{Classifier} & \makecell[c]{Feature} & \makecell[c]{Test \\ Accuracy} & \makecell[c]{Training \\ Time} \\ \midrule
            35 & 15 & GBLinear & IEMG & 100 & 9.29 \\ 
            35 & 15 & GBLinear & MAV & 100 & 8.89 \\ 
            35 & 15 & GBLinear & MAV1 & 100 & 8.39 \\ 
            35 & 15 & GBLinear & RMS & 100 & 5.32 \\
            35 & 15 & Bagging SVM & MAV & 100 & 4.06 \\
            35 & 15 & Bagging SVM & MAV1 & 100 & 2.9 \\
            35 & 15 & Bagging SVM & RMS & 100 & 6.69 \\ \midrule
            30 & 20 & GBLinear & IEMG & 98.75 & 8.23 \\
            30 & 20 & GBLinear & MAV1 & 98.75 & 4.26 \\
            30 & 20 & GBLinear & RMS & 98.75 & 8.31 \\
            30 & 20 & Stacking SVM & MAV1 & 98.75 & 2.61 \\ \midrule
            25 & 25 & GBLinear & IEMG & 98 & 8.08 \\ \midrule
            20 & 30 & Bagging SVM & RMS & 98.33 & 4.3 \\
            20 & 30 & GBLinear & IEMG & 98.33 & 6.13 \\                
            \bottomrule
        \end{tabular}
    \end{table}
\end{document}

相关内容