I'm trying to create a table with:
- different formatting across cells
- footnotes
- minipages
- coloured rows
For the coloured rows I'm trying to use xcolor with the [table] option.
However, this throws an error with the >{\bfseries} column spec. I'm using MiKTeX 2.9.6972 on Windows 10 x64 and version 2.4k of the array package as described in here, and XeLaTeX to compile (although PDFLaTeX seems to generate the same error). This works if I switch off the xcolor package, but then the \rowcolor command is no longer available.
My question is two-fold:
- Is it possible to use
[table]{xcolor}and{array}together? - If not, is there an alternative to color a row of a table?
MWE:
\documentclass{article}
\usepackage[table]{xcolor} % works if we remove the 'table' option, but then we don't have access to cellcolor/rowcolor
%\usepackage{xcolor}
\usepackage{booktabs}
% force the new array package to be loaded.
\usepackage{tabularx}
% https://texfaq.org/FAQ-wholerow
\newcolumntype{@}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
\begin{document}
\begin{tabular}{>{\bfseries}@p{5.5cm}^r}
Col A & Col B \\
\midrule
\rowstyle{\bfseries\itshape\large}This row should be large, bold, italics with shading & So this cell too. \\
\rowcolor{blue}This bold but shaded & this just normal.\footnote{I.e., no extra mark-up} \\
Remark & \multicolumn{1}{c}{\begin{minipage}[t]{3.5cm}\raggedright {\footnotesize Some cells are included as a minipage to accommodate extra text.}\end{minipage}} \\
\midrule
\end{tabular}
\end{document}
The error I get is:
! Use of \@startpbox doesn't match its definition.
<inserted text> \@startpbox {
>{\bfseries }@p{5.5cm}^r}
l.19 \begin{tabular}{>{\bfseries}@p{5.5cm}^r}
If you say, e.g., `\def\a1{...}', then you must always put `1' after `\a',
since control sequence names are made up of letters only.
The macro here has not been followed by the required stuff, so I'm ignoring
it.
! LaTeX Error: Command \bfseries invalid in math mode.
greyis not defined. If I replacegreyby blue, your code runs through on my machine. – Mar 03 '19 at 07:19