\documentclass[]{article}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{multicol,booktabs,tabularx}
% Table settings
\renewcommand{\aboverulesep}{1pt}
\renewcommand{\belowrulesep}{1pt}
\begin{document}
\begin{tabularx}{\textwidth}{@{}X l@{}}
This is Header 1 & This is Header 2 \\
\toprule
\rowcolor{Apricot}
This is Text 1 & This is Text 2 \\\midrule
This is Text 1 & This is Text 2 \\\midrule
This is Text 1 & This is Text 2 \\
\bottomrule
\end{tabularx}
\end{document}
I have the above table MWE using tabularx
, and I am trying to colour the row from the table. However, due to the use of my \aboverulesep
and \belowrulesep
, I now have gaps above and below my table row that is not coloured.
Also, because of the use of my @{}
on either side of the table to 'remove' the excess padding on the sides of the table, the row colour is being applied in those padding as well.
Qn 1: How can I colour the aforementioned gaps (arising due to the \aboverulesep
) in, while maintaining the rule separation?
Qn 2: How to remove the colour from the two sides of the table?
EDIT
This is in response to Zarko's answer. I want to maintain the use of @{}
on either side to remove the padding. If I were to adapt this into your answer, like so:
% @Zarko's answer
\documentclass{article}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{booktabs, cellspace, tabularx}
% Table settings
\renewcommand{\aboverulesep}{0pt}
\renewcommand{\belowrulesep}{0pt}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\begin{document}
\begin{tabularx}{\textwidth}{@{}SX Sl@{}}% <-- S is append for activate additional vertical space
This is Header 1 & This is Header 2 \\
\toprule
\rowcolor{Apricot}
This is Text 1 & This is Text 2 \\\midrule
This is Text 1 & This is Text 2 \\\midrule
This is Text 1 & This is Text 2 \\
\bottomrule
\end{tabularx}
\end{document}
and so my second question (Qn2) is still unresolved.. For Qn 1, I prefer to use the solution by @Skillmon with \renewcommand{\arraystretch}{1.15}
as I need not add a new package.
Best Answer
One of possibilities is to use
cellspace
package:First the vertical space around
booktabs
rules i reduced to zero pt, than is increased by macro\cellspacetoplimit
and\cellspacebottomlimit
to desired vertical (colored) gap:Addendum: works around to second part of question. It need to introduce fake column (or to have zero distance between columns or white space with width of two
\tabcolsep
):This time without additional package but with tricks how to use
\rowcolor
(for details see documentation for packagecolortbl
):Addendum (2): After four years ... Now I would use new table package
tabularray
. Using it for the MWE in above addendum is code simpler: