
我可以突出顯示表格中的一行(見下文),但它不以文字為中心。有沒有辦法解決這個問題?
代碼:
\documentclass[11pt]{article}
\usepackage{color, colortbl,booktabs}
\definecolor{Gray}{gray}{0.9}
\begin{document}
\begin{table}[!htbp]
\centering
\begin{tabular}{llccc}
\midrule
&&Mean&Sigma&Total Points \& Costs\\
\midrule
2014 & Unused & 377 & 214 & 1,618,193\\ [0.5ex]
& Deducted & 213 & 141 & 565,792\\ [0.5ex]
& Carryover & 245 & 91 & 1,052,401 \\ [0.5ex]
& Used & 308 & 187 & 1,115,463\\ [0.5ex]
\rowcolor{Gray}
& Costs (dollars) & 590 & 343 & 2,162,652 \\ [0.5ex]
\bottomrule
\end{tabular}
\end{table}
\end{document}
輸出:
答案1
文字僅在彩色面板中看起來相對較高,因為您有像 C 和 d 這樣的高字符以及數字,並且除了 () 的一小部分之外沒有帶有下降部分的字符
但是,您可以新增零寬度規則,無論您想要調整行中內容的大小,高度和深度如何:
\documentclass[11pt]{article}
\usepackage{color, colortbl,booktabs}
\definecolor{Gray}{gray}{0.9}
\begin{document}
\begin{table}[!htbp]
\centering
\begin{tabular}{llccc}
\midrule
&&Mean&Sigma&Total Points \& Costs\\
\midrule
2014 & Unused & 377 & 214 & 1,618,193\\ [0.5ex]
& Deducted & 213 & 141 & 565,792\\ [0.5ex]
& Carryover & 245 & 91 & 1,052,401 \\ [0.5ex]
& Used & 308 & 187 & 1,115,463\\ [0.5ex]
\rowcolor{Gray}
\rule[-1cm]{0pt}{2.4cm} & Costs (dollars) & 590 & 343 & 2,162,652 \\ [0.5ex]
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
我建議使用此程式碼makecell
並使用xcolor
選項加載table
- 無需加載colortbl
,該選項即可完成。我去掉了彩色行和底部之間的白色細條,並用於siunitx
更好地對齊數字。最後我提出了另一個更令我滿意的灰色陰影…:-)
\documentclass[11pt]{article}
\usepackage{booktabs, makecell}
\usepackage[table, svgnames]{xcolor}
\usepackage{siunitx}
\definecolor{Gray}{gray}{0.9}
\begin{document}
\begin{table}[!htbp]
\centering
\sisetup{table-format=3.0, table-number-alignment=center, group-separator={,}}
\setlength{\extrarowheight}{0.5ex}
\begin{tabular}{llSSS[table-format=7.0]}
\midrule
&&{Mean}&{Sigma}& {\makecell{Total Points \\[-0.5ex] \& Costs}} \\
\midrule
2014 & Unused & 377 & 214 & 1618193\\
& Deducted & 213 & 141 & 565792\\
& Carryover & 245 & 91 & 052401 \\
& Used & 308 & 187 & 1115463\\
\rowcolor{WhiteSmoke!70!Lavender}
& Costs (dollars) & 590 & 343 & 2162652 \\
\noalign{\vskip-\aboverulesep}
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
使用新包tabularray
:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\begin{document}
\begin{table}[htb]
\centering
\sisetup{table-format=3.0,
group-separator={,}}
\begin{tblr}{colspec={ll *{2}{Q[c,m,si]}
Q[c,m,si={table-format=7},wd=6em]},
rows={rowsep=1pt},
row{Z}={bg=gray9, abovesep+=3pt, belowsep+=3pt},
}
\toprule
& & {{{Mean}}}
& {{{Sigma}}}
& {{{Total Points \& Costs}}}
\\
\midrule
2014 & Unused & 377 & 214 & 1618193 \\
& Deducted & 213 & 141 & 565792 \\
& Carryover & 245 & 91 & 052401 \\
& Used & 308 & 187 & 1115463 \\
& Costs (dollars)
& 590 & 343 & 2162652 \\
\bottomrule
\end{tblr}
\end{table}
\end{document}
答案4
以下是透過設定\extrarowheight=0.5ex
in {NiceTabular}
which 可以以與 相容的方式為行著色booktabs
。
\documentclass[11pt]{article}
\usepackage{booktabs}
\usepackage[svgnames]{xcolor}
\usepackage{siunitx}
\definecolor{Gray}{gray}{0.9}
\usepackage{nicematrix}
\begin{document}
\begin{table}[!htbp]
\centering
\sisetup{table-format=3.0, table-number-alignment=center, group-separator={,}}
\setlength{\extrarowheight}{0.5ex}
\begin{NiceTabular}{llSSS[table-format=7.0]}[colortbl-like]
\midrule
&&{Mean}&{Sigma}& \Block{}{Total Points \\[-0.5ex] \& Costs} \\
\midrule
2014 & Unused & 377 & 214 & 1618193\\
& Deducted & 213 & 141 & 565792\\
& Carryover & 245 & 91 & 052401 \\
& Used & 308 & 187 & 1115463\\
\rowcolor{WhiteSmoke!70!Lavender}
& Costs (dollars) & 590 & 343 & 2162652 \\
\bottomrule
\end{NiceTabular}
\end{table}
\end{document}
您需要多次編譯(因為nicematrix
在背景使用 PGF/Tikz 節點)。