I want to highlight a few rows in a table, and used \rowcolor
as per the first table. Well, this results in the row coloring being wider than I desire, so I thought the simple fix would be to adjust the overhang of the row via the optional parameter
\rowcolor{cyan!20}[1pt]
But, this yields the result shown in the second table. The overhang was applied to each cell -- I just want to control the overhang of the entire row, not each cell. That is, I want a solid colored row, but with the overhang adjusted on the left and the right of the row.
Code:
\documentclass{article}
\usepackage{booktabs}
\usepackage{xcolor}
\usepackage{colortbl}
\begin{document}
\begin{tabular}{clc}
$n$ & Text & $f(n)$ \\
\cmidrule(lr){1-1}
\cmidrule(lr){2-2}
\cmidrule(lr){3-3}
\rowcolor{cyan!20}
1 & abc & 2 \\
2 & abc & 1 \\ \rowcolor{cyan!20}
7 & abc & 3 \\
8 & abc & 2 \\
9 & abc & 1 \\
10 & abc & 2 \\
11 & abc & 2 \\
\bottomrule
\end{tabular}
\quad
\begin{tabular}{clc}
$n$ & Text & $f(n)$ \\
\cmidrule(lr){1-1}
\cmidrule(lr){2-2}
\cmidrule(lr){3-3}
\rowcolor{cyan!20}[1pt]% <---- only change from above is the "[0pt]"
1 & abc & 2 \\
2 & abc & 1 \\ \rowcolor{cyan!20}
7 & abc & 3 \\
8 & abc & 2 \\
9 & abc & 1 \\
10 & abc & 2 \\
11 & abc & 2 \\
\bottomrule
\end{tabular}
\end{document}