texblog

Hidden text with LaTeX colored multi-row tables

When multirow cells in LaTeX tables are colored, the text is partially hidden as illustrated by the example below. This happens because the color of the second row is added after typesetting the text of the first row.

\documentclass[12pt]{article}
\usepackage{colortbl}
\usepackage[table]{xcolor}
\usepackage{multirow}

\definecolor{lightgray}{gray}{0.9}
\rowcolors{2}{white}{lightgray}
\begin{document}

\begin{table}[ht]
\caption{Colored multirow table}
\begin{center}
\begin{tabular}{cc}
\hline
\multirow{2}{*}{Multi-row}&Single-row\\
&Single-row\\
Single-row&Single-row\\
\hline
\end{tabular}
\end{center}
\label{default}
\end{table}%

\end{document}

 

Solution:

There is a simple solution to this problem. If the multirow command is placed in the last possible row and its first argument is made negative, the text is added only after the color and becomes fully visible.

\documentclass[12pt]{article}
\usepackage{colortbl}
\usepackage[table]{xcolor}
\usepackage{multirow}

\definecolor{lightgray}{gray}{0.9}
\rowcolors{2}{white}{lightgray}
\begin{document}

\begin{table}[ht]
\caption{Colored multirow table}
\begin{center}
\begin{tabular}{cc}
\hline
&Single-row\\
\multirow{-2}{*}{Multi-row}&Single-row\\
Single-row&Single-row\\
\hline
\end{tabular}
\end{center}
\label{default}
\end{table}%

\end{document}
Exit mobile version