虽然在 中可以工作,但\cellcolor
package 中的命令似乎colortbl
在 环境中不起作用。这是一个最小的例子:tabulary
tabular
\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}
还有什么需要添加,或者有解决方法吗?
答案1
tabulary
检测colortbl
并插入针对该情况的修改后的定义,但在 2001 年\cellcolor
“最近”添加:并且未更新以匹配。colortbl
tabulary
% \changes{v0.1j}{2001/02/13}{\cs{cellcolor} (唐纳德·阿瑟诺)}
\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}