拆分表格列类似于 html 中的嵌套表格

拆分表格列类似于 html 中的嵌套表格

我想在第一行的第二列和第三列下放置一行。单元格的内容应为“ET in sec.”,第二个单元格的内容应为“Memory in MB”。第三列也一样。可以吗?因为每个单元格的第一个值是用连字符分隔的已用时间,第二个值是 Memory in MB。

\documentclass{article}
\begin{document}

    \begin{center}
    \begin{tabular}{ |c|c|c|c| } 
    \hline
    Random AST depth & Static schedule evaluation & Demand evaluation ET in sec. \\ \hline
    & ET in sec. | Memory in MB & ET in sec. | Memory in MB \\ \hline
    1 & 0.009 - 2.971 & 0.091 - 5.536 \\ \hline
    2 & 0.003 - 2.921 & 0.009 - 3.178 \\ \hline
    3 & 0.005 - 3.646 & 0.009 - 4.037 \\ \hline
    4 & 0.019 - 7.872 & 0.019 - 9.548 \\ \hline
    5 & 0.097 - 13.091 & 0.123 - 21.288 \\ \hline
    6 & 0.044 - 46.332 & 0.053 - 86.475 \\ \hline
    7 & 0.064 - 57.778 & 0.122 - 112.154 \\ \hline
    8 & 0.501 - 155.338 & 0.761 - 453.930 \\ \hline
    9 & 4.029 - 198.215 & 2.276 - 866.845 \\ \hline
    10 & 7.439 - 1346.093 & 9.757 - 1652.442 \\ \hline
    11 & 30.57 - 1368.750 & 43.098 - 1915.167 \\ 
    \hline
    \end{tabular}
    \end{center}

\end{document}

在此处输入图片描述

答案1

你没有给出最终的显示效果,我不清楚你想要什么效果,我按照我的猜测帮你实现了一个,你看看是否符合你的要求。

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\begin{document}
\begin{table}
\caption{title}
\begin{tblr}
{
colspec      = {X[c,m]X[c,m]X[c,m]X[c,m]X[c,m]},
cell{1}{2,4} = {c=2}{},
cell{1}{1}   = {r=2}{},
hlines,
vlines,
}
Random AST depth & Static schedule evaluation &              & Demand evaluation ET in sec. &              \\
                 & ET in sec.                 & Memory in MB & ET in sec.                   & Memory in MB \\
1                & 0.009                      & 2.971        & 0.091                        & 5.536        \\
2                & 0.003                      & 2.921        & 0.009                        & 3.178        \\
3                & 0.005                      & 3.646        & 0.009                        & 4.037        \\
4                & 0.019                      & 7.872        & 0.019                        & 9.548        \\
5                & 0.097                      & 13.091       & 0.123                        & 21.288       \\
6                & 0.044                      & 46.332       & 0.053                        & 86.475       \\
7                & 0.064                      & 57.778       & 0.122                        & 112.154      \\
8                & 0.501                      & 155.338      & 0.761                        & 453.930      \\
9                & 4.029                      & 198.215      & 2.276                        & 866.845      \\
10               & 7.439                      & 1346.093     & 9.757                        & 1652.442     \\
11               & 30.57                      & 1368.750     & 43.098                       & 1915.167     \\
\end{tblr}
\end{table}
\begin{table}
\caption{title}
\begin{tblr}
{
colspec       = {Q[co=1,c,m]*{4}{Q[co=1,si={table-format=4.3},c,m]}},
cell{1}{2,4}  = {c=2}{},
cell{1}{1}    = {r=2}{},
hline{1,Z}    = {wd=.08em},
hline{2}      = {2-Z}{wd=.05em},
hline{3}      = {wd=.05em},
row{odd[3-Z]} = {bg=gray9!50},
column{1}     = {guard},
row{1-2}      = {guard},
}
Random AST depth & Static schedule evaluation &              & Demand evaluation ET in sec. &              \\
                 & ET in sec.                 & Memory in MB & ET in sec.                   & Memory in MB \\
1                & 0.009                      & 2.971        & 0.091                        & 5.536        \\
2                & 0.003                      & 2.921        & 0.009                        & 3.178        \\
3                & 0.005                      & 3.646        & 0.009                        & 4.037        \\
4                & 0.019                      & 7.872        & 0.019                        & 9.548        \\
5                & 0.097                      & 13.091       & 0.123                        & 21.288       \\
6                & 0.044                      & 46.332       & 0.053                        & 86.475       \\
7                & 0.064                      & 57.778       & 0.122                        & 112.154      \\
8                & 0.501                      & 155.338      & 0.761                        & 453.930      \\
9                & 4.029                      & 198.215      & 2.276                        & 866.845      \\
10               & 7.439                      & 1346.093     & 9.757                        & 1652.442     \\
11               & 30.57                      & 1368.750     & 43.098                       & 1915.167     \\
\end{tblr}
\end{table}
\end{document}

在此处输入图片描述

答案2

连字符会分散注意力,并妨碍数字对齐。这里有两个建议;在这两个建议中,都省略了垂直线,因为它们无用且不利于阅读。

\documentclass{article}
\usepackage{booktabs,siunitx}

\begin{document}

\begin{center}
\begin{tabular}{
  @{}
  c
  S[table-format=2.3]
@{\hspace{3\tabcolsep}}
  S[table-format=4.3]
  S[table-format=2.3]
  S[table-format=4.3]
  @{}
} 
\toprule
\smash{\begin{tabular}[t]{@{}c@{}} Random \\ AST depth \end{tabular}} &
  \multicolumn{2}{c}{Static schedule evaluation} &
  \multicolumn{2}{c@{}}{Demand evaluation} \\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
& {ET (s)} & {Memory (MB)} & {ET (s)} & {Memory (MB)} \\
\midrule
1 & 0.009 & 2.971 & 0.091 & 5.536 \\
2 & 0.003 & 2.921 & 0.009 & 3.178 \\
3 & 0.005 & 3.646 & 0.009 & 4.037 \\
4 & 0.019 & 7.872 & 0.019 & 9.548 \\
5 & 0.097 & 13.091 & 0.123 & 21.288 \\
6 & 0.044 & 46.332 & 0.053 & 86.475 \\
7 & 0.064 & 57.778 & 0.122 & 112.154 \\
8 & 0.501 & 155.338 & 0.761 & 453.930 \\
9 & 4.029 & 198.215 & 2.276 & 866.845 \\
10 & 7.439 & 1346.093 & 9.757 & 1652.442 \\
11 & 30.57 & 1368.750 & 43.098 & 1915.167 \\ 
\bottomrule
\end{tabular}
\end{center}

\begin{center}
\begin{tabular}{
  @{}
  c
  S[table-format=2.3]
  S[table-format=4.3]
  S[table-format=2.3]
  S[table-format=4.3]
  @{}
} 
\toprule
\smash{\begin{tabular}[t]{@{}c@{}} Random \\ AST \\ depth \end{tabular}} &
  \multicolumn{4}{c@{}}{Evaluation} \\
\cmidrule(l){2-5}
& \multicolumn{2}{c}{Static schedule} &
  \multicolumn{2}{c@{}}{Demand} \\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
& {ET} & {Memory} & {ET} & {Memory} \\
\midrule
1 & 0.009 & 2.971 & 0.091 & 5.536 \\
2 & 0.003 & 2.921 & 0.009 & 3.178 \\
3 & 0.005 & 3.646 & 0.009 & 4.037 \\
4 & 0.019 & 7.872 & 0.019 & 9.548 \\
5 & 0.097 & 13.091 & 0.123 & 21.288 \\
6 & 0.044 & 46.332 & 0.053 & 86.475 \\
7 & 0.064 & 57.778 & 0.122 & 112.154 \\
8 & 0.501 & 155.338 & 0.761 & 453.930 \\
9 & 4.029 & 198.215 & 2.276 & 866.845 \\
10 & 7.439 & 1346.093 & 9.757 & 1652.442 \\
11 & 30.57 & 1368.750 & 43.098 & 1915.167 \\ 
\midrule[\heavyrulewidth]
\multicolumn{5}{@{}l@{}}{ET in seconds, Memory in MB}
\end{tabular}
\end{center}

\end{document}

在此处输入图片描述

相关内容