我正在尝试创建一个包含以下内容的表:
- 不同单元格的格式不同
- 脚注
- 迷你页面
- 彩色行
对于彩色行,我尝试使用xcolor
该[table]
选项。
但是,这会引发列规范错误>{\bfseries}
。我在 Windows 10 x64 上使用 MiKTeX 2.9.6972 和 2.4k 版本的软件包,array
如中所述这里和 XeLaTeX 进行编译(尽管 PDFLaTeX 似乎会产生相同的错误)。如果我关闭包,这可以正常工作xcolor
,但\rowcolor
命令将不再可用。
我的问题有两个:
- 可以
[table]{xcolor}
和{array}
一起使用吗? - 如果没有的话,有没有其他方法可以为表格的某一行添加颜色?
梅威瑟:
\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}
我收到的错误是:
! 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.