
Tenho uma tabela e gostaria de destacar algumas linhas.
Estou usando:
\usepackage[table]{xcolor}
e:
\rowcolor{gray!50}
que produz:
Quero destacar a linha inteira com um bloco sólido de cor,
like this!
Qualquer conselho seria apreciado!
MWE:
\begin{table*}[ht]
\centering
\setlength{\tabcolsep}{1mm}
\begin{tabular}{cccccc}
\hline\hline
\thead{Name} & \thead{Observing\\Frequency\\(MHz)} & \thead{Mean Standard Deviation of\\On-Pulse Phase Bins} & \thead{Peak Systematic\\Variability} & \thead{Average Systematic\\Variability} & \thead{Noisy\\Variability} \\
\hline
\rowcolor{gray!50}
B1747 & 1400 & 8.83 & 281.00 & 0.95 & 8.68 \\
B1747 & 2030 & 3.61 & 6.15 & 0.09 & 3.66 \\
B1747 & 1500 & 2.37 & 5.47 & 0.19 & 2.35 \\
B1347 & 820 & 1.44 & 4.59 & 0.09 & 1.43 \\
\rowcolor{gray!50}
B1921 & 820 & 5.46 & 34.23 & 2.56 & 3.87 \\
C1921 & 1500 & 5.16 & 12.00 & 1.12 & 4.86 \\
D1921 & 1400 & 4.93 & 22.66 & 1.84 & 3.96 \\
B1921 & 2030 & 2.82 & 14.01 & 1.29 & 2.25 \\
\hline
\end{tabular}
\caption{caption}
\label{var_table}
\end{table*}
Responder1
Para adicionar espaço entre as colunas em uma tabela, \rowcolor
você deve usar \setlength{\tabcolsep}{5mm}
para uma alteração uniforme do espaço. Se as alterações não forem uniformes, você poderá inserir colunas adicionais que inserem apenas espaço (usando <{\hspace{5mm}}
). Neste último caso, você deve usar &
s adicionais para adicionar as colunas vazias.
\documentclass[]{scrartcl}
\usepackage[table]{xcolor}
\begin{document}
Wrong:
\begin{tabular}[]{@{\hspace{5mm}}c@{\hspace{10mm}}c@{\hspace{5mm}}}
\hline
\rowcolor{gray!50}a&b\\
\hline
\end{tabular}
\\good:
{
\setlength{\tabcolsep}{5mm}
\begin{tabular}[]{cc}
\hline
\rowcolor{gray!50}a&b\\
\hline
\end{tabular}
}
\\not uniform:
{
\setlength{\tabcolsep}{0mm}
\begin{tabular}[]{c<{\hspace{7mm}}c<{\hspace{12mm}}c<{\hspace{5mm}}}
\hline
\rowcolor{gray!50}&a&b\\
\hline
\end{tabular}
}
\end{document}
Na primeira tabela não funcionará, enquanto a segunda e a terceira tabelas dão os resultados desejados:
Responder2
Com o tabularray
pacote é simples:
\documentclass[twocolumn]{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\begin{document}
\begin{table*}[ht]
\centering
\begin{talltblr}[
note{a} = {Mean Standard Deviation}
]{
hline{1,Z}=1pt, hline{2}=0.6pt,
colspec = {X[l,m] X[c,m, si={table-format=4}]
X[c,m, si={table-format=1.2}]
X[c,m, si={table-format=3.2}]
X[c,m, si={table-format=1.2}]
X[c,m, si={table-format=1.2}]
},
row{1} = {font=\small\bfseries},
}
Name & {{{Observing Frequency (MHz)}}}
& {{{MSD\TblrNote{a} of On-Pulse Phase Bins}}}
& {{{Peak Systematic Variability}}}
& {{{Average Systematic Variability}}}
& {{{ Noisy Variability }}} \\
\SetRow{bg=gray8}
B1747 & 1400 & 8.83 & 281.00 & 0.95 & 8.68 \\
B1747 & 2030 & 3.61 & 6.15 & 0.09 & 3.66 \\
B1747 & 1500 & 2.37 & 5.47 & 0.19 & 2.35 \\
B1347 & 820 & 1.44 & 4.59 & 0.09 & 1.43 \\
\SetRow{gray8}
B1921 & 820 & 5.46 & 34.23 & 2.56 & 3.87 \\
C1921 & 1500 & 5.16 & 12.00 & 1.12 & 4.86 \\
D1921 & 1400 & 4.93 & 22.66 & 1.84 & 3.96 \\
B1921 & 2030 & 2.82 & 14.01 & 1.29 & 2.25 \\
\end{talltblr}
\end{table*}
\end{document}
Responder3
O ambiente {NiceTabular}
do pacote nicematrix
fornece (quando a chave colortbl-like
está em vigor) comandos semelhantes aos do clássico colortbl
para colorir linhas, colunas e células.
Você terá a saída esperada mesmo se usar @{\hspace{...}
para aumentar o espaço entre duas colunas.
Além disso, você não verá linhas brancas finas, independentemente do visualizador de PDF usado.
\documentclass{article}
\usepackage{nicematrix}
\usepackage{makecell}
\begin{document}
\begin{table*}[ht]
\centering
\setlength{\tabcolsep}{1mm}
\begin{NiceTabular}{c@{\hspace{2cm}}ccccc}[colortbl-like]
\hline\hline
\RowStyle{\bfseries}
\thead{Name} & \thead{Observing\\Frequency\\(MHz)} & \thead{Mean Standard Deviation of\\On-Pulse Phase Bins} & \thead{Peak Systematic\\Variability} & \thead{Average Systematic\\Variability} & \thead{Noisy\\Variability} \\
\hline
\rowcolor{gray!50}
B1747 & 1400 & 8.83 & 281.00 & 0.95 & 8.68 \\
B1747 & 2030 & 3.61 & 6.15 & 0.09 & 3.66 \\
B1747 & 1500 & 2.37 & 5.47 & 0.19 & 2.35 \\
B1347 & 820 & 1.44 & 4.59 & 0.09 & 1.43 \\
\rowcolor{gray!50}
B1921 & 820 & 5.46 & 34.23 & 2.56 & 3.87 \\
C1921 & 1500 & 5.16 & 12.00 & 1.12 & 4.86 \\
D1921 & 1400 & 4.93 & 22.66 & 1.84 & 3.96 \\
B1921 & 2030 & 2.82 & 14.01 & 1.29 & 2.25 \\
\hline
\end{NiceTabular}
\caption{caption}
\label{var_table}
\end{table*}
\end{document}
Você precisa de várias compilações (porque nicematrix
usa nós PGF/Tikz nos bastidores).