I have a problem with changing background of the table cells/rows.
This is the code I use:
\documentclass{article}
\usepackage[skip=0.333\baselineskip]{caption}
\usepackage{booktabs,tabularx,ragged2e}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage[table]{xcolor}
\begin{document}
\renewcommand{\arraystretch}{1.3}
\newcolumntype{Y}{>{\hsize=.7\hsize\RaggedRight\arraybackslash}X}
\newcolumntype{B}{X}
\begin{table}
\caption{Sources and targets}
\begin{tabularx}{\textwidth}{p{1cm}@{}*{4}{Y}@{}}
%% table header
\toprule
\rowcolor{lightgray}\multicolumn{2}{r@{}}{List targets} $\rightarrow$ & \multicolumn{3}{c@{}}{Targets} \\
\cmidrule(l){3-5}
\rowcolor{lightgray}\multicolumn{2}{l@{}}{\cellcolor{lightgray}$\downarrow$ Sources} & Target 1 & Target 2 & Target 3 \\
\midrule
%% body of table
\multirow{3}{2cm}{\rotatebox{90}{\parbox{\linewidth}{sources}}} &\cellcolor{lightgray}Source 1 & Description 10
& Description 11
& Description 12 \\
\addlinespace % <-- use whitespace as a simple yet very effective divider
&\cellcolor{lightgray}Source 2 (additional info)
& Description 20
& Description 21
& Description 22, \par
Description 23, \par
Description 24 \\
\addlinespace % ditto
&\cellcolor{lightgray}Source 3 & Description 30
& Description 31
& Description 32, \par
Description 33, \par
Description 34 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
Can anyone help me to make it look better? Without this white space between cells, and also this vertical column (sources) should also have the same gray background.
Best Answer
Adaptations:
addlinespace
,toprule
,midrule
andbottomrule
to remove the whitespace (and usehline
instead)...{List targets $\rightarrow$}
\newcolumntype{a}{>{\columncolor{lightgray}}Y}
(from How do I color table columns?)\multirow{-3}{...}{...}
in the last line of the 3 lines, else the background gray will be over the text (see texblog: Coloring multi-row tables in LaTeX)Code:
Result: