I'm trying to create a new columntype with options as in the source below, and all option work fine, except for the b option, which gives this error message:
! Undefined control sequence.
\KV@xcol@b #1->\columncolor
{#1}
When I use the \columncolor} directly, as in the second tabularx below, ther is no problem. Why?
\documentclass{article}
\usepackage[papersize={90mm,60mm},margin=5mm]{geometry}
\usepackage{array,xkeyval,xcolor,colortbl,tabularx,ragged2e}
\pagestyle{empty}\parindent0pt
% keys for columntype x:
\makeatletter
\define@key{xcol}{w}{\hsize=#1\hsize} % relative width (summarize to 1)
\define@key{xcol}{f}{\leavevmode\color{#1}} % foreground color
\define@key{xcol}{b}{\columncolor{#1}} % background color
\define@key{xcol}{r}[]{\RaggedLeft} % justify right
\define@key{xcol}{l}[]{\RaggedRight} % justify left (the default)
\define@key{xcol}{c}[]{\Centering} % center
\makeatother
\newcolumntype{x}[1]{>{\RaggedRight\setkeys{xcol}{#1}}X}
\begin{document}
% the b=yellow should make \colorcolumn{yellow}, but \columncolor is undefined?
\begin{tabularx}{80mm}[t]{|x{f=blue,b=yellow,w=.7,c}|x{w=.3,r}|}\hline
Hello & World\\\hline
\end{tabularx}
\bigskip
% using \columncolor directly: no problem:
\begin{tabularx}{50mm}[t]{|>{\columncolor{yellow}}x{f=blue,w=.7,r}|x{w=.3}|}\hline
Hello & World\\\hline
\end{tabularx}
\end{document}
\multicolumnas the first entry in a cell. Your setting of keys makes\columncolornot the first thing in the cell. – Werner Oct 22 '15 at 14:53\columncolorin a cell.\columncolor{yellow} Hellowould give the same error. As you hide it in a setkeys-command you are too late. Use\cellcolor. – Ulrike Fischer Oct 22 '15 at 14:53