# Coloring rows problem

I need fill table rows with color, but I have few problem with it:

1. If I do this some columns are overlaid by background (first pic - multirow).

2. I see white borders. (I don't understand why - they should be here)

3. I do not know how I can set color for columns at right side table (mirrored L) on "none" or "white".

This is what I have:

This is what I need:

\documentclass{article}

\usepackage{xcolor,colortbl}
\usepackage{geometry}                 % customize page layout
\usepackage{array}
\usepackage{multirow}                 % multirow for table (rowspan)

\geometry{paper=a4paper, landscape,hmargin=28.5mm,vmargin=20mm}

\setlength\parindent{0cm}   % no indent for whole document
\setlength{\tabcolsep}{0cm}   % padding either side of each column (only horizontal)

\definecolor{Gray}{gray}{0.85}

% document start
\begin{document}

\newcolumntype{M}[1]{>{\columncolor{Gray}\centering\arraybackslash}m{\dimexpr#1-\arrayrulewidth\relax}}
\newcolumntype{P}[1]{>{\columncolor{Gray}\centering\arraybackslash}p{\dimexpr#1-\arrayrulewidth\relax}}

\newcolumntype{X}[1]{>{\columncolor{Gray}\arraybackslash}p{\dimexpr#1-\arrayrulewidth\relax}}
\newcolumntype{Y}[1]{>{\columncolor{Gray}\raggedright\arraybackslash}p{\dimexpr#1-\arrayrulewidth\relax}}

\begin{tabular}{
| P{1.4cm}
| M{1.4cm}
| M{1.4cm}
| P{7.6cm}
| P{6.4cm}
| P{1.2cm}
| P{1.2cm}
| P{1.2cm}
| P{2.2cm}
|
}

\hline
\multicolumn{4}{|c|}{\rule[-0.4cm]{0cm}{1cm} B} & \multicolumn{5}{c|}{q} \\

\hline
a & SSW \par \footnotesize{(xx)} & xxx \footnotesize{(xxx)} & b & & x & d & e &  \\\cline{1-8}

\rule[-0.8cm]{0cm}{1cm} & & &
\multirow{8}{7.6cm}{%
\rule[-.4cm]{0.5cm}{0cm}
\begin{tabular}{
X{2.5cm}
X{0.9cm}
Y{1.6cm}
Y{1.6cm}
}
one question & & $\bigcirc$ yes & $\bigcirc$ no \\
second question & & $\bigcirc$ left & $\bigcirc$ right \\
third question & & $\bigcirc$ yes & $\bigcirc$ no \\
fourth question & & $\bigcirc$ yes & $\bigcirc$ no \\
fifth question & & $\bigcirc$ yes & $\bigcirc$ no \\
sixsth question & & $\bigcirc$ mono & $\bigcirc$ color \\
\end{tabular} %
}
& & & & & \\
\cline{1-3}\cline{5-8}
\rule[-0.8cm]{0cm}{1cm} & & & & & & & & \\\cline{1-3}\cline{5-8}
\multicolumn{2}{|P{2.8cm}}{\rule{0cm}{1cm}}  & & & & \multicolumn{3}{P{2.8cm}}{\rule{0cm}{1cm}}  &\\
\hline

\end{tabular}

% document end
\end{document}
• So you don't need the first row (with B and q)? May 19 '15 at 10:04
• no... thx - updated May 19 '15 at 10:10
• Why are you nesting tabulars? May 19 '15 at 10:10
• Because i want alignment columns in responses. May 19 '15 at 10:13

## 1 Answer

Some notes about your code and also the changes:

• Loading \usepackage[table]{xcolor} also loads colortbl.
• You can load \usepackage{array, multirow} together (saves one line!).
• New column types should be defined here
• Remember that the paper format is loaded in the document class and you can apply the margins and the landscape as options of the geometry package.

As a personal note, I suggest you load all the packages together, then all the various tweaks in the preamble and then the document. It's not a rule, but it's better organised. It's up to your preference, though.

I loaded the hhline package for coloring the rules, then used \rowcolors{2}{Gray}{Gray} for the rows, and the command \cellcolor{white} to isolate the white cells (except the top). There is no need to nest tabulars, my solution uses one tabular only.

## Code

\documentclass[a4paper]{article}
\usepackage[hmargin=28.5mm,vmargin=20mm,landscape]{geometry}
\usepackage[table]{xcolor}
\usepackage{hhline}
\usepackage{array, multirow}                 % multirow for table (rowspan)

\setlength\parindent{0cm}   % no indent for whole document
\setlength{\tabcolsep}{0cm}   % padding either side of each column (only horizontal)

\definecolor{Gray}{gray}{0.85}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{\dimexpr#1-\arrayrulewidth\relax}}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{\dimexpr#1-\arrayrulewidth\relax}}

\newcolumntype{X}[1]{>{\arraybackslash}p{\dimexpr#1-\arrayrulewidth\relax}}
\newcolumntype{Y}[1]{>{\hspace{2pt}\raggedright\arraybackslash}p{\dimexpr#1-\arrayrulewidth\relax}}

\renewcommand*{\arraystretch}{1.5}

\newcommand{\myl}{%
\hhline{*3{>{\arrayrulecolor{black}}-}*4{>{\arrayrulecolor[gray]{.85}}-}|*3{>{\arrayrulecolor{black}}-}}
}

\begin{document}
\rowcolors{2}{Gray}{Gray}
\begin{tabular}{|P{1.4cm}|M{1.4cm}|M{1.3cm}|Y{4cm}Y{1.5cm}Y{1.5cm}|P{7.6cm}|P{1.2cm}|P{1.2cm}|P{1.2cm}|P{2.2cm}|
}
\hline
\rowcolor{white}
\multicolumn{6}{|c|}{B} & \multicolumn{5}{c|}{q} \\ \hline
a   & SSW \par \footnotesize{(xx)} & xxx \footnotesize{(xxx)} & \multicolumn{3}{c|}{b} & & x & d & e & \cellcolor{white} \\ \hhline{*{10}{-}}
& & & one question & $\bigcirc$ yes & $\bigcirc$ no & & & & & \cellcolor{white} \\ \myl
& & & second question & $\bigcirc$ left & $\bigcirc$ right & & & & & \cellcolor{white} \\ \myl
& & & third question & $\bigcirc$ yes & $\bigcirc$ no & & & & & \cellcolor{white} \\ \myl
\multicolumn{3}{|c|}{} & fourth question & $\bigcirc$ yes & $\bigcirc$ no & & \multicolumn{3}{c}{\cellcolor{white}} & \cellcolor{white} \\
\multicolumn{3}{|c|}{} & fourth question & $\bigcirc$ yes & $\bigcirc$ no & & \multicolumn{3}{c}{\cellcolor{white}} & \cellcolor{white} \\
\multicolumn{3}{|c|}{\multirow{-3}{*}{}} & sixth question & $\bigcirc$ mono & $\bigcirc$ color & & \multicolumn{3}{c}{\multirow{-3}{*}{\cellcolor{white}}} & \cellcolor{white} \\ \hline
\end{tabular}
\end{document}
• yeah thx but there is still white lines and table looks different now (in multicolumn where are questions is not padding and there is too big line height) May 19 '15 at 12:37
• @LajdákMarek You can try adding a negative vertical skip, but as far as I know there is currently no universal solution to this. Coloured tables usually display those thin white lines. I'm looking into it, though. May 19 '15 at 15:31