latex 表之间的间距不同

latex 表之间的间距不同

现在我正在使用 latex 代码绘制表格。
但是,表格行与行之间的间距似乎不合适(略有偏差)

这是我做的表格 在此处输入图片描述

但是,我想要这种类型的表格(澄清一下,使用 powerpoint :/ ,宽度为 2 列)

在此处输入图片描述


此外,还需要类似下表的类型(1 列宽度)

在此处输入图片描述

我几乎花了三天时间...
这就是‘混乱’的代码!

\begin{table*}[]\label{table_test}\centering
\renewcommand{\arraystretch}{1.3}
\renewcommand{\tabcolsep}{4 mm}
\caption{ }
\begin{tabular}{clccccccccccl}
\hline
\multicolumn{13}{c}{(1) MachineLearning-based}           
\\ \hline
\multicolumn{2}{c|}{Method}    
\multicolumn{2}{c|}{Method}
& A01 & A02 & A03 & A04 & A05 & A06 & A07 & A08 & \multicolumn{1}{c|}{A09} & 
\multicolumn{2}{c}{Mean}                                                                                    \\ \hline 
~~~~~~~~
~~~~~~~~
\multicolumn{2}{c|}{Model3}                                  
& \multicolumn{1}{l}{\begin{tabular}[c]{@{}l@{}}00.00\\ $\pm$00.00\end{tabular}}        
& \multicolumn{1}{l}{\begin{tabular}[c]{@{}l@{}}00.00\\ $\pm$00.00\end{tabular}} 
& \multicolumn{1}{l}{\begin{tabular}[c]{@{}l@{}}00.00\\ $\pm$00.00\end{tabular}}      
& \multicolumn{1}{l}{\begin{tabular}[c]{@{}l@{}}00.00\\ $\pm$00.00\end{tabular}}     
& \multicolumn{1}{l}{\begin{tabular}[c]{@{}l@{}}00.00\\ $\pm$00.00\end{tabular}}
& \multicolumn{1}{l}{\begin{tabular}[c]{@{}l@{}}00.00\\ $\pm$00.00\end{tabular}}      
& \multicolumn{1}{l}{\begin{tabular}[c]{@{}l@{}}00.00\\ $\pm$00.00\end{tabular}}     
& \multicolumn{1}{l}{\begin{tabular}[c]{@{}l@{}}00.00\\ $\pm$00.00\end{tabular}}    
& \multicolumn{1}{l|}{\begin{tabular}[c]{@{}l@{}}00.00\\ $\pm$00.00\end{tabular}}
& \multicolumn{2}{l}{\begin{tabular}[c]{@{}l@{}}00.00\\ $\pm$00.00\end{tabular}}                                  \\

\rowcolor[HTML]{EFEFEF}
\multicolumn{2}{c|}{\cellcolor[HTML]{EFEFEF}\textbf{Model4}} 
& \multicolumn{1}{l}{\cellcolor[HTML]{EFEFEF}\textbf{\begin{tabular}[c]{@{}l@{}}\textbf{00.00}\\ \textbf{$\pm$00.00}\end{tabular}}} 
& \multicolumn{1}{l}{\cellcolor[HTML]{EFEFEF}\textbf{\begin{tabular}[c]{@{}l@{}}\textbf{00.00}\\ \textbf{$\pm$00.00}\end{tabular}}} 
& \multicolumn{1}{l}{\cellcolor[HTML]{EFEFEF}\textbf{\begin{tabular}[c]{@{}l@{}}\textbf{00.00}\\ \textbf{$\pm$00.00}\end{tabular}}} 
& \multicolumn{1}{l}{\cellcolor[HTML]{EFEFEF}\textbf{\begin{tabular}[c]{@{}l@{}}\textbf{00.00}\\ \textbf{$\pm$00.00}\end{tabular}}} 
& \multicolumn{1}{l}{\cellcolor[HTML]{EFEFEF}\textbf{\begin{tabular}[c]{@{}l@{}}\textbf{00.00}\\ \textbf{$\pm$00.00}\end{tabular}}} 
& \multicolumn{1}{l}{\cellcolor[HTML]{EFEFEF}\textbf{\begin{tabular}[c]{@{}l@{}}\textbf{00.00}\\ \textbf{$\pm$00.00}\end{tabular}}} 
& \multicolumn{1}{l}{\cellcolor[HTML]{EFEFEF}\textbf{\begin{tabular}[c]{@{}l@{}}\textbf{00.00}\\ \textbf{$\pm$00.00}\end{tabular}}} 
& \multicolumn{1}{l}{\cellcolor[HTML]{EFEFEF}\textbf{\begin{tabular}[c]{@{}l@{}}\textbf{00.00}\\ \textbf{$\pm$00.00}\end{tabular}}} 
& \multicolumn{1}{l|}{\cellcolor[HTML]{EFEFEF}\textbf{\begin{tabular}[c]{@{}l@{}}\textbf{00.00}\\ \textbf{$\pm$00.00}\end{tabular}}} 
& \multicolumn{2}{l}{\cellcolor[HTML]{EFEFEF}\textbf{\begin{tabular}[c]{@{}l@{}}\textbf{00.00}\\ \textbf{$\pm$00.00$^{**}$}\end{tabular}}} 
\\ \hline
\end{tabular}

\begin{tabular}{clccccccccccl}
\hline
\multicolumn{13}{c}{(2) DeepLearning-based} 

~~~~~~~~~~~
SAME as above
~~~~~~~~~~~      

答案1

以下解决方案试图简化表格的“外观”,主要是通过删除垂直规则并使用更少的水平规则。我也会放弃使用\rowcolor和,\cellcolor因为给单元格和整行上色似乎除了提供华丽和廉价的娱乐之外没有任何作用——至少对于手头的表格来说是这样。

下面的代码使用了一个快捷宏——名字不是很有想象力\myarray——来替换看起来相当复杂的

\multicolumn{1}{l}{\textbf{\begin{tabular}[c]{@{}l@{}}\textbf{00.00}\\ \textbf{$\pm$00.00}\end{tabular}}} 

更加易于管理

\myarray[\boldmath]{00.00 \\ \pm 00.00}

如果你不需要粗体的主要参数\myarray,只是省略了宏的可选参数,即[\boldmath]


在此处输入图片描述

\documentclass{beamer}
\usepackage{booktabs}
%% Define a handy shortcut macro:
\newcommand\myarray[2][]{\ensuremath{#1\begin{array}[t]{r} #2 \end{array}}}

\begin{document}
\begin{frame}[t]
\frametitle{A table with two subpanels}

\tiny
\setlength{\tabcolsep}{0pt}
\centerline{%
\begin{tabular*}{1.1\textwidth}{ l @{\extracolsep{\fill}}*{10}{c} }

\toprule
Method  
& A01 & A02 & A03 & A04 & A05 & A06 & A07 & A08 & A09 & Mean \\ 
\midrule
\addlinespace[2mm]
\multicolumn{4}{l}{(1) Machine Learning-based} \\ 
\addlinespace
Model2                                 
& \myarray{01.00 \\ \pm 00.00}        
& \myarray{02.00 \\ \pm 00.00} 
& \myarray{03.00 \\ \pm 00.00}      
& \myarray{04.00 \\ \pm 00.00}     
& \myarray{05.00 \\ \pm 00.00}
& \myarray{06.00 \\ \pm 00.00}  
& \myarray{07.00 \\ \pm 00.00}     
& \myarray{08.00 \\ \pm 00.00}    
& \myarray{08.00 \\ \pm 00.00}
& \myarray{05.00 \\ \pm 00.00} 
\\
\addlinespace
Model3                                 
& \myarray{21.00 \\ \pm 00.00}        
& \myarray{22.00 \\ \pm 00.00} 
& \myarray{23.00 \\ \pm 00.00}      
& \myarray{24.00 \\ \pm 00.00}     
& \myarray{25.00 \\ \pm 00.00}
& \myarray{26.00 \\ \pm 00.00}  
& \myarray{27.00 \\ \pm 00.00}     
& \myarray{28.00 \\ \pm 00.00}    
& \myarray{29.00 \\ \pm 00.00}
& \myarray{25.00 \\ \pm 00.00} 
\\
\addlinespace[4mm]
\multicolumn{4}{l}{(2) Deep Learning-based} \\
\addlinespace
\textbf{Model4} 
& \myarray[\boldmath]{01.00 \\ \pm 00.00} 
& \myarray[\boldmath]{02.00 \\ \pm 00.00} 
& \myarray[\boldmath]{03.00 \\ \pm 00.00}
& \myarray[\boldmath]{04.00 \\ \pm 00.00} 
& \myarray[\boldmath]{05.00 \\ \pm 00.00} 
& \myarray[\boldmath]{06.00 \\ \pm 00.00} 
& \myarray[\boldmath]{07.00 \\ \pm 00.00} 
& \myarray[\boldmath]{08.00 \\ \pm 00.00} 
& \myarray[\boldmath]{09.00 \\ \pm 00.00} 
& \myarray[\boldmath]{05.00 \\ \pm 00.00\rlap{${}^{**}$}}\\
\addlinespace
\textbf{Model5} 
& \myarray[\boldmath]{41.00 \\ \pm 00.00} 
& \myarray[\boldmath]{42.00 \\ \pm 00.00} 
& \myarray[\boldmath]{43.00 \\ \pm 00.00}
& \myarray[\boldmath]{44.00 \\ \pm 00.00} 
& \myarray[\boldmath]{45.00 \\ \pm 00.00} 
& \myarray[\boldmath]{46.00 \\ \pm 00.00} 
& \myarray[\boldmath]{47.00 \\ \pm 00.00} 
& \myarray[\boldmath]{48.00 \\ \pm 00.00} 
& \myarray[\boldmath]{49.00 \\ \pm 00.00} 
& \myarray[\boldmath]{45.00 \\ \pm 00.00}\\
\bottomrule
\end{tabular*}
}
\end{frame}
\end{document}

答案2

一个实验,如何使用tabularray包及其库booktabssiunitx加载相同名称的包)以及changepage扩展表\textwidth的包来编写表:

\documentclass{beamer}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\usepackage{changepage}

\begin{document}
\begin{frame}[t]
\frametitle{A table with two subpanels}

\begin{adjustwidth}{-1.5em}{-1.5em}
\tiny
\sisetup{minimum-integer-digits=2,
         detect-weight,
         mode=text}
\SetTblrStyle{remark}{fg=black!80}
\begin{talltblr}[
       entry = none,
       label = none,
remark{Note} = {\sisetup{minimum-integer-digits=1}  % <---
                Symbols *, **, and *** denote significance at the
                \qty{10}{\%}, \qty{5}{\%} and \qty{1}{\%} levels, respectively.}
                ]{colsep = 0pt,
                 colspec = {    l 
                           *{9}{X[c, si]}
                                X[c, si={table-format=-2.2{**}}]
                           },
                 row{1}  = {guard},
                 row{3-Z}={rowsep=0pt},
                 row{odd[3-7]}  = {abovesep=1ex},
                 row{even[8-Z]} = {abovesep=1ex},
                 row{8-Z}={font=\bfseries},
                 }
    \toprule
Method
    & A01 & A02 & A03 & A04 & A05 & A06 & A07 & A08 & A09 & Mean \\
    \midrule
\SetCell[c=4]{l, guard}    (1) Machine Learning-based
    &       &       &       &       &       &       &       &       &       &           \\
Model 2
    & 01.00 & 02.00 & 03.00 & 04.00 & 05.00 & 06.00 & 07.00 & 08.00 & 09.00 & 10.00     \\
    & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00 
    & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00         \\
Model 3
    & 01.00 & 02.00 & 03.00 & 04.00 & 05.00 & 06.00 & 07.00 & 08.00 & 09.00 & 10.00     \\
    & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00
    & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00         \\

\SetCell[c=4]{l, guard}    (2) Deep Learning-based
    &       &       &       &       &       &       &       &       &       &           \\
Model 4
    & 01.00 & 02.00 & 03.00 & 04.00 & 05.00 & 06.00 & 07.00 & 08.00 & 09.00 & 10.00     \\
    & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00
    & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00\TblrNote{**}   \\
Model 5
    & 01.00 & 02.00 & 03.00 & 04.00 & 05.00 & 06.00 & 07.00 & 08.00 & 09.00 & 10.00     \\
    & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00
    & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00     & \pm 00.00         \\
    \bottomrule
\end{talltblr}
\end{adjustwidth}
\end{frame}
\end{document}

在此处输入图片描述

相关内容