如何在行之间添加 10pt 的垂直空间以使其不那么拥挤,同时仍保持行颜色?

如何在行之间添加 10pt 的垂直空间以使其不那么拥挤,同时仍保持行颜色?
\begin{document}
\begin{table}[H]
    \centering
    \begin{tabular}{ccccccccc}
    \toprule
    String Tension & \multicolumn{8}{c}{Rebound Height / m $\pm$ 0.05 m}\\
    kg/ $\pm$ 0.5 & Trial 1 & Trial 2 & Trial 3 & Trial 4 & Trial 5 & Trial 6 & Trial 7 & Trial 8\\
    \midrule
\rowcolor[rgb]{0.902,0.902,0.902} 
    15 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 &
    6.345 & 7.345 & 8.345\\
   \rowcolor[rgb]{0.949,0.949,0.949}
    20 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.902,0.902,0.902} 
    25 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.949,0.949,0.949}
    30 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.902,0.902,0.902} 
    35 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
    \bottomrule
    \end{tabular}
    \caption{Raw Data}
    \label{tab:Raw Data}
\end{table}
\end{document}

我想在每行之间添加 10pt 的垂直空间,并在反弹高度行和试验之间添加 5 pt 的空间。当我执行 \vspace{10pt} 时,额外的空间是白色的,我不知道如何为使用 vspace 生成的额外空间着色。此外,vspace 在反弹高度和试验之间不起作用。谢谢![输出当前代码1

答案1

一种方法是设置\extrarowheight为 10pt(array需要包)。

\documentclass{article}
\usepackage{booktabs,array}
\usepackage[table]{xcolor}
\begin{document}
\begin{table}[ht]
  \renewcommand\extrarowheight{10pt}
    \centering
    \begin{tabular}{ccccccccc}
    \toprule
    String Tension & \multicolumn{8}{c}{Rebound Height / m $\pm$ 0.05 m}\\
    kg/ $\pm$ 0.5 & Trial 1 & Trial 2 & Trial 3 & Trial 4 & Trial 5 & Trial 6 & Trial 7 & Trial 8\\
    \midrule
\rowcolor[rgb]{0.902,0.902,0.902} 
    15 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 &
    6.345 & 7.345 & 8.345\\
   \rowcolor[rgb]{0.949,0.949,0.949}
    20 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.902,0.902,0.902} 
    25 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.949,0.949,0.949}
    30 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.902,0.902,0.902} 
    35 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
    \bottomrule
    \end{tabular}
    \caption{Raw Data}
    \label{tab:Raw Data}
\end{table}
\end{document}

在此处输入图片描述

如果希望行数据垂直居中,可以在每行的单个条目上添加 5pt(上方和下方)的堆栈间隙:

\documentclass{article}
\usepackage{booktabs,stackengine}
\usepackage[table]{xcolor}
\begin{document}
\begin{table}[ht]
    \centering
    \begin{tabular}{ccccccccc}
    \toprule
    String Tension & \multicolumn{8}{c}{Rebound Height / m $\pm$ 0.05 m}\\
    kg/ $\pm$ 0.5 & Trial 1 & Trial 2 & Trial 3 & Trial 4 & Trial 5 & Trial 6 & Trial 7 & Trial 8\\
    \midrule
\rowcolor[rgb]{0.902,0.902,0.902} 
    \addstackgap[5pt]{15} & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 &
    6.345 & 7.345 & 8.345\\
   \rowcolor[rgb]{0.949,0.949,0.949}
    \addstackgap[5pt]{20} & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.902,0.902,0.902} 
    \addstackgap[5pt]{25} & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.949,0.949,0.949}
    \addstackgap[5pt]{30} & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.902,0.902,0.902} 
    \addstackgap[5pt]{35} & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
    \bottomrule
    \end{tabular}
    \caption{Raw Data}
    \label{tab:Raw Data}
\end{table}
\end{document}

在此处输入图片描述

或者,可以更新 的值\arraystretch。但是,这种方法不会设置特定的点值增加,而是以某种方式与默认的 baselineskip 成比例地增加空间:

\documentclass{article}
\usepackage{booktabs,array}
\usepackage[table]{xcolor}
\begin{document}
\begin{table}[ht]
  \renewcommand\arraystretch{1.5}
    \centering
    \begin{tabular}{ccccccccc}
    \toprule
    String Tension & \multicolumn{8}{c}{Rebound Height / m $\pm$ 0.05 m}\\
    kg/ $\pm$ 0.5 & Trial 1 & Trial 2 & Trial 3 & Trial 4 & Trial 5 & Trial 6 & Trial 7 & Trial 8\\
    \midrule
\rowcolor[rgb]{0.902,0.902,0.902} 
    15 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 &
    6.345 & 7.345 & 8.345\\
   \rowcolor[rgb]{0.949,0.949,0.949}
    20 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.902,0.902,0.902} 
    25 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.949,0.949,0.949}
    30 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
\rowcolor[rgb]{0.902,0.902,0.902} 
    35 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
    \bottomrule
    \end{tabular}
    \caption{Raw Data}
    \label{tab:Raw Data}
\end{table}
\end{document}

在此处输入图片描述

答案2

使用新tabularray包的一个解决方案,请参阅加拿大运输安全局

\documentclass{article}

\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
    
\definecolor{oddrows}{rgb}{0.902,0.902,0.902}
\definecolor{evenrows}{rgb}{0.949,0.949,0.949}
\begin{table}[ht]
    \centering
    \begin{tblr}{
            colspec=ccccccccc,
            row{odd}=oddrows,
            row{even}=evenrows,
            row{1,2}=white,
        }
        \toprule
        String Tension & \SetCell[c=8]{c}{Rebound Height / m $\pm$ 0.05 m}\\
        kg/ $\pm$ 0.5 & Trial 1 & Trial 2 & Trial 3 & Trial 4 & Trial 5 & Trial 6 & Trial 7 & Trial 8\\
        \midrule
        15 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
        20 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
        25 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
        30 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
        35 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
        \bottomrule
    \end{tblr}
    \caption{Raw Data}
    \label{tab:Raw Data}
\end{table}
\end{document}

tabularray 解决方案

默认情况下,垂直间距会增加。如果要进一步增加间距,可以指定参数rowsep(default 2pt)。您还可以为rowsep前两行指定不同的间距。

\documentclass{article}

\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
    
\definecolor{oddrows}{rgb}{0.902,0.902,0.902}
\definecolor{evenrows}{rgb}{0.949,0.949,0.949}
\begin{table}[ht]
    \centering
    \begin{tblr}{
            colspec=ccccccccc,
            row{odd}=oddrows,
            row{even}=evenrows,
            rowsep=5pt,
            row{1,2}={white,rowsep=2.5pt}
        }
        \toprule
        String Tension & \SetCell[c=8]{c}{Rebound Height / m $\pm$ 0.05 m}\\
        kg/ $\pm$ 0.5 & Trial 1 & Trial 2 & Trial 3 & Trial 4 & Trial 5 & Trial 6 & Trial 7 & Trial 8\\
        \midrule
        15 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
        20 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
        25 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
        30 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
        35 & 1.345 & 2.345 & 3.345 & 4.345 & 5.345 & 6.345 & 7.345 & 8.345\\
        \bottomrule
    \end{tblr}
    \caption{Raw Data}
    \label{tab:Raw Data}
\end{table}
\end{document}

增加了垂直间距的 tabularray

还有其他参数,例如,abovesepbelowsep分别控制每行上方和下方的间距。请Table 3.1参阅tabularray 文档以获取完整列表。

相关内容