12

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?

6
  • 2
    Welcome to TeX.SX! Good minimal example!
    – egreg
    Jun 20, 2014 at 9:55
  • 9
    such naive optimism to expect two packages written by the same person might actually work together:-) Jun 20, 2014 at 9:58
  • (Nice test file: I'll look later) Jun 20, 2014 at 11:09
  • 1
    This is fixed in tabulary 0.10 which has been submitted to ctan so should appear there in a day or so. Jun 21, 2014 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) Jun 23, 2014 at 10:03

1 Answer 1

10

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)}

enter image description here

\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}}
{\typeout{bad}}


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


\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}
11
  • 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, 2014 at 9:19
  • 1
    @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:-) Jun 21, 2014 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, 2014 at 8:28
  • @Neptilo wow I can confirm that, no idea: I'll look later, can't look now. Jun 23, 2014 at 8:33
  • @Neptilo whatever it is it's unrelated to colortbl, as you get the same without it. Jun 23, 2014 at 8:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .