
Posso destacar uma linha em uma tabela (veja abaixo), mas ela não está centralizada no texto. Existe uma maneira de corrigir isso?
Código:
\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}
Saída:
Responder1
O texto só parece relativamente alto no painel colorido, pois você tem caracteres altos como C e d e os dígitos e nenhum caractere com descendentes além de uma pequena parte do ()
No entanto, você pode adicionar uma regra de largura zero com qualquer altura e profundidade que desejar para ajustar o tamanho do conteúdo na linha:
\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}
Responder2
Proponho este código, usando makecell
e carregando xcolor
com a opção table
– desnecessário carregar colortbl
, a opção faz isso. Retirei a fina faixa branca entre a linha colorida e a parte inferior, e usei siunitx
para um melhor alinhamento dos números. Por último proponho outro tom de cinza que me agrada mais… :-)
\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}
Responder3
Com novo pacote 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}
Responder4
Aqui está o que, ao definir \extrarowheight=0.5ex
which {NiceTabular}
, é possível colorir as linhas de uma forma compatível com 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}
Você precisa de várias compilações (porque nicematrix
usa nós PGF/Tikz nos bastidores).