# Table with multirow and rowcolors

For a template I'm creating at the moment I need a table with alternating rowcolors in the first two columns and one multirow (third column) containing an image. This multirow should not react to the rowcolors command. Here is an example image of a table created with Word.

In addition to that the content of the table gets inserted by using variables (MWE). If a variable gets no value (is empty) the whole line of the table should disappear.

Normally I have to color every cell by hand because rowcolors and multirow apparently don't work well together. Since the rows disappear if their variable is left empty the rowcolors are likely to get out of order after each entry. Is there any way to get alternating rowcolors and a multirow in a table without having to change the cellcolor manually each time?

Thanks a lot for your help and sorry for my English ...

\documentclass[a4paper,pagesize]{scrartcl}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{array}
\usepackage{color}
\usepackage[table]{xcolor}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}
\def\leer{}
\def\FirstRow{Row1}
\def\SecondRow{Row2}
\def\ThirdRow{Row3}
\def\FourthRow{}
\def\FifthRow{Row5}
\def\SixthRow{Row6}

\begin{table}[ht] \centering
\renewcommand{\arraystretch}{2}
%\rowcolors{1}{}{blue}
\begin{tabular}{| >{\bfseries}M{.15\textwidth} | M{.25\textwidth} | M{.4\textwidth} |}
\hline
\rowcolors{1}{blue}{white}
\ifx\FirstRow\leer \else FirstRow & \FirstRow & \multirow{5}{*}{\includegraphics[width=.4\textwidth]{example-image-golden}} \\ \hhline{--~|} \fi
\ifx\SecondRow\leer \else SecondRow & \SecondRow & \\ \hhline{--~|} \fi
\ifx\ThirdRow\leer \else ThirdRow & \ThirdRow & \\ \hhline{--~|} \fi \rowcolor{blue}
\ifx\FourthRow\leer \else FourthRow & \FourthRow & \\ \hhline{--~|} \fi
\ifx\FifthRow\leer \else FifthRow & \FifthRow & \\ \hhline{--~|} \fi
\ifx\SixthRow\leer \else SixthRow & \SixthRow & \\ \hline \fi
\end{tabular}
\end{table}

\end{document}

• What is happening is that \rownum is incrementing twice per row, once due to the \hhline. One can place [\hline] in \rowcolors, but it crashes with \hhline or \cline. – John Kormylo Sep 7 '15 at 15:27

Something like this?

This is task for two tables. Outer table in the first cell contain inner table with colored rows and in second cell is image.

\documentclass[a4paper,pagesize]{scrartcl}
\usepackage{tabularx}
\usepackage{graphicx}
%\usepackage{multirow}
%\usepackage{hhline}
\usepackage{array}
%\usepackage{color}
\usepackage[table]{xcolor}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}
\def\leer{}
\def\FirstRow{Row1}
\def\SecondRow{Row2}
\def\ThirdRow{Row3}
\def\FourthRow{}
\def\FifthRow{Row5}
\def\SixthRow{Row6}

\begin{table}[ht] \centering
\renewcommand{\arraystretch}{2}
\begin{tabular}{| c@{}| M{.4\textwidth} |}
\hline
\rowcolors{1}{blue}{white}
\begin{tabular}{|@{}>{\bfseries}M{.15\textwidth} | M{.25\textwidth}|@{}}
\ifx\FirstRow\leer  \else FirstRow  & \FirstRow     \\
\ifx\SecondRow\leer \else SecondRow & \SecondRow    \\  \fi
\ifx\ThirdRow\leer  \else ThirdRow  & \ThirdRow     \\  \fi
\ifx\FourthRow\leer \else FourthRow & \FourthRow    \\  \fi
\ifx\FifthRow\leer  \else FifthRow  & \FifthRow     \\  \fi
\ifx\SixthRow\leer  \else SixthRow  & \SixthRow     \\  \fi
\end{tabular}   &
\includegraphics[width=\hsize]{example-image-golden} \\
\hline
\end{tabular}
\end{table}
\end{document}


If there is less than four rows, the colored rows appear with white space above and below inner table. I comment package which I not use in above image. The packages color and multirow is superfluous The task of the first is also performed width xcolor, second one is not used anymore.

• You might try \rowcolors[\hline]{1}{blue}{} – John Kormylo Sep 7 '15 at 15:30
• @JohnKormylo, I test your suggestion. Its result without tweak of tables is worse as it is now. – Zarko Sep 7 '15 at 17:07