
表内の行を強調表示することはできますが (下記参照)、テキストの中央に配置されません。これを修正する方法はありますか?
コード:
\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
で{NiceTabular}
、 と互換性のある方法で行に色を付けることができます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 ノードが使用されるため)。