# Use \cellcolor in \tabulary

The \cellcolor command from package colortbl doesn't seem to have any effect in a tabulary environment, though it works in tabular. Here is a minimal example:

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{tabulary}
\usepackage{colortbl}

\begin{document}

\begin{tabular}{c}
\cellcolor{green}42
\end{tabular}

\begin{tabulary}{\textwidth}{C}
\cellcolor{green}42
\end{tabulary}

\end{document}


Is there something more to add, or a workaround?

• Welcome to TeX.SX! Good minimal example! – egreg Jun 20 '14 at 9:55
• such naive optimism to expect two packages written by the same person might actually work together:-) – David Carlisle Jun 20 '14 at 9:58
• (Nice test file: I'll look later) – David Carlisle Jun 20 '14 at 11:09
• This is fixed in tabulary 0.10 which has been submitted to ctan so should appear there in a day or so. – David Carlisle Jun 21 '14 at 18:46
• @DavidCarlisle I am not sure if it is the right place, but it seems that there are 2 typos in documentation dated 2014/06/11: "as if the natuaral length was equal to \tymax). This is initially set to twice the text width.." (natuAral and double dot) – Przemysław Scherwentke Jun 23 '14 at 10:03

tabulary detects colortbl and inserts modified definitions for that case, but \cellcolor was "recently" added to colortbl in 2001: and tabulary wasn't updated to match.

% \changes{v0.1j}{2001/02/13}{\cs{cellcolor} (Donald Arseneau)}

\documentclass[a4paper]{article}

\usepackage{colortbl}
\usepackage{tabulary}
\usepackage{etoolbox}

\begin{document}
\makeatletter% needs to be after begin document

\patchcmd\@mkpream
{\let\CT@row@color\relax}
{\let\CT@row@color\relax\let\CT@cell@color\relax}
{\typeout{good}}

\patchcmd\TY@classz
{\CT@row@color}
{\CT@row@color\CT@cell@color}
{\typeout{good}}

\makeatletter

\begin{tabular}{>{\columncolor{red}}c}
a
\\
\cellcolor{green}42
\end{tabular}

\begin{tabulary}{\textwidth}{>{\columncolor{red}}C}
a
\\
\cellcolor{green}42
\end{tabulary}

\end{document}

• I have no idea what these lines mean, but it works. :) The first \patchcmd does not seem to be needed. What is it for? – Neptilo Jun 21 '14 at 9:19
• @Neptilo actually it's probably not needed, I just looked at all the places where tabulary modified colortbl and made it do something for cellcolor whenever it did something for rowcolor:-) but actually you are unlikely to have cellcolor in the tabular preamble argument so it probably isn't needed (does no harm though:-) – David Carlisle Jun 21 '14 at 10:15
• Interestingly, when adding \usepackage[T1]{fontenc}, the error happens again, along with Package tabulary Warning: No suitable columns. What's happening? – Neptilo Jun 23 '14 at 8:28
• @Neptilo wow I can confirm that, no idea: I'll look later, can't look now. – David Carlisle Jun 23 '14 at 8:33
• @Neptilo whatever it is it's unrelated to colortbl, as you get the same without it. – David Carlisle Jun 23 '14 at 8:43