1

I have a table and I would like to highlight some rows.

I am using:

\usepackage[table]{xcolor}

and:

\rowcolor{gray!50}

which produces:

I want to highlight the entire row with a solid block of colour,

like this!

Any advice would be appreciated!


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*}
  • 2
    You should really provide a complete minimal working example (MWE), which reproduces your issue, begins at \documentclass, ends at \end{document} and includes every necessary package. With the question as it is, I can only guess that you try to add additionalspace inbetween columns, either with @{} or by changing the length of tabcolsep. – Skillmon Apr 26 '17 at 19:31
  • 3
    ...most likely @{\hspace{5pt}} or something similar. – Werner Apr 26 '17 at 19:33
  • 1
    I have strictly no problem with the code you posted. There must be something else not in the post. – Bernard Apr 26 '17 at 20:31
  • 1
    Good to see, that you posted a MWE, but you're lacking the necessary packages, the \documentclass and \begin{document}...\end{document}. (and what is \thead?) – Skillmon Apr 26 '17 at 20:35
2

To add space between the columns in a table using \rowcolor you should use \setlength{\tabcolsep}{5mm} for a uniform space change. If the changes shouldn't be uniform, you might insert additional columns which only insert space (using <{\hspace{5mm}}). In the latter case, you have to use additional &s to add the empty columns.

\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}

In the first table it won't work, while the second and third tables gives the desired results:

results

  • Thank you! Anyway to remove the faint but noticeable line between the cells? – user1551817 Apr 26 '17 at 20:19
  • 1
    @user1551817 Those spaces are normal for \rowcolor. They are there even without any changes in spacing. They are the fault of the pdfviewer. Open the pdf with Xpdf and they are gone. They shouldn't be there after printing. – Skillmon Apr 26 '17 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.