rowcolor command from colortbl package leaves unwanted gaps in shading between columns
@{\extracolsep{\fill}}
introduce additional space between columns which is not covered byrowcolor
- in second line you have
\rowcolor{newgray}[20pt][20pt]
which should be only\rowcolor{newgray}
- coloring rows and use rules from
booktabs
doesn't gives nice result, instead them i suggest lines provided by packageboldline
- for more vertical space in cells i suggest to use
calspace
\documentclass{article}
\usepackage[table]{xcolor} % it call and enhance colortbl
\definecolor{newgray}{RGB}{196,196,196}
\usepackage{booktabs, threeparttable}
\usepackage{tabularx} % new
\usepackage{boldline} % new (part of shipunov bundle)
\usepackage{cellspace} % new
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\addparagraphcolumntypes{X}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\begin{document}
\begin{threeparttable}
\centering
\begin{tabularx}{\textwidth}{ S{>{\hsize=0.4\hsize}L}
>{\hsize=0.2\hsize}L
>{\hsize=0.2\hsize}C
>{\hsize=0.2\hsize}R}
\multicolumn{4}{c}{\textbf{Random Table}} \\
\hlineB{2}
Item & Case 1 & Case 2 & Case 3 \\
\hlineB{1.75}
\rowcolor{newgray}
first thing, & \tnote{a}245 & \tnote{b}25e-6 & \tnote{c}79e-6 \\
\rowcolor{newgray}
second thing & \tnote{a}450 & --- & \tnote{b}24e-6 \\
third thing & \tnote{d}2e-6 & \tnote{c}4123.5 & \tnote{b}2e-6 \\
fourth thing & --- & 1e6 & no data \\
\hlineB{2}
\end{tabularx}
\begin{tablenotes}
\item[a] some explanation
\item[b] this is why \dots
\item[c] see reference awesome
\item[d] hello world
\item
\end{tablenotes}
\end{threeparttable}
\end{document}
edit: if you like to have simpler solution with less nice table (which width is still equal to text width), than try the following:
\documentclass{article}
\usepackage[table]{xcolor} % it call and enhance colortbl
\definecolor{newgray}{RGB}{196,196,196}
\usepackage{booktabs, threeparttable}
\usepackage{tabularx} % new
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\begin{document}
\begin{threeparttable}
\centering
\renewcommand\arraystretch{1.2}
\begin{tabularx}{\textwidth}{ L L C R }
\multicolumn{4}{c}{\textbf{Random Table}} \\
\hline
Item & Case 1 & Case 2 & Case 3 \\
\hline
\rowcolor{newgray}
first thing, & \tnote{a}245 & \tnote{b}25e-6 & \tnote{c}79e-6 \\
\rowcolor{newgray}
second thing & \tnote{a}450 & --- & \tnote{b}24e-6 \\
third thing & \tnote{d}2e-6 & \tnote{c}4123.5 & \tnote{b}2e-6 \\
fourth thing & --- & 1e6 & no data \\
\hline
\end{tabularx}
\begin{tablenotes}
\item[a] some explanation
\item[b] this is why \dots
\item[c] see reference awesome
\item[d] hello world
\item
\end{tablenotes}
\end{threeparttable}
\end{document}
note:
S{X}
specifier means that to selectedX
column is added vertical space defined by\setlength\cellspacetoplimit{4pt} \setlength\cellspacebottomlimit{4pt}
with
>{\hsize=0.4\hsize}
and>{\hsize=0.2\hsize}
is changed ratio between columns widths (first column has width equal0.4\textwidth
, other three have width equal0.2\textwidth
each)the first solution can be simplified by removing
cellspace
stuff and for more vertical spaces around cells contents use simpler\renewcommand\arraystretch{1.2}
:\documentclass{article} \usepackage[table]{xcolor} % it call and enhance colortbl \definecolor{newgray}{RGB}{196,196,196} \usepackage{booktabs, threeparttable} \usepackage{tabularx} % new \usepackage{boldline} % new (part of shipunov bundle) \newcolumntype{C}{>{\centering\arraybackslash}X} \newcolumntype{L}{>{\raggedright\arraybackslash}X} \newcolumntype{R}{>{\raggedleft\arraybackslash}X} \begin{document} \begin{threeparttable} \centering \renewcommand\arraystretch{1.2} \begin{tabularx}{\textwidth}{>{\hsize=0.4\hsize}L >{\hsize=0.2\hsize}L >{\hsize=0.2\hsize}C >{\hsize=0.2\hsize}R} %% table body and table notes %% \end{threeparttable} \end{document}