9

I am writing a table with colored rows using the tabupackage (2.10). For example

\documentclass[12pt]{article}
\usepackage{tabu}
\usepackage[table]{xcolor}
\begin{document}
\begin{table}
    \rowcolors{2}{red}{blue}
    \begin{tabu}{cc}
        \toprule
        Row1 & A \\
        Row2 & B \\
        Row3 & C \\
        \bottomrule
    \end{tabu}
\end{table}
\end{document}

I have also tried with \taburowcolors 2{red ... blue} but the colors never show up at all.

I am aware of the issue at the github repo https://github.com/tabu-fixed/tabu/issues and even after manually updating to the 2.10 release, the problem still persists for me.

Does anyone know if the problem has been fixed? If so, how can I get the colored table.

It is worth to mention that I am using the tabuenviroment as I will be using the columns with custom lengths X[n]. Is there any other alternative to tabu where I can set up the length of the columns?

C. Zhihao
  • 265

2 Answers2

5

like this?

enter image description here

Why not use tabu package is explained in comments below your question ...

Solution can be use tabularx instead of tabu and boldline for horizontal lines with adjusted thickness (instead booktabs rules, which have (white) space above/below rule):

\documentclass[12pt]{article}
\usepackage{boldline}% for rules, part of Shipunov bundle
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage[table]{xcolor}
\newcounter{tblerows}% see https://tex.stackexchange.com/questions/297345/
                     % why-is-the-start-row-of-rowcolors-ignored-in-tabularx
\expandafter\let\csname c@tblerows\endcsname\rownum

\begin{document}
\begin{table}
    \rowcolors{2}{red!30}{blue!30}
    \begin{tabularx}{0.5\linewidth}{>{\hsize=1.5\hsize}C
                                    >{\hsize=0.5\hsize}C
                                    }
        \hlineB{2}
        Row1 & AA AA \\
        Row2 & B \\
        Row3 & C \\
        \hlineB{2}
    \end{tabularx}
\end{table}
\end{document}
Zarko
  • 296,517
5

The same question has been submitted in GitHub, see Simplest MWE to have an alternating row color #18. The proposed solution for the version v2.9 2019/01/11 of tabu comments some commands, see Figure. For further details, please check the solution provided in GitHub.

enter image description here

I try this fix in tabu.sty (v2.9) and does what you are looking for. Maybe it will be fixed in the next release of tabu.

In any case, please consider the above remark of Ulrike Fisher and thus the solution proposed by Zarco.

Ñako
  • 3,626