xcolor 和 everycr 问题

xcolor 和 everycr 问题

我尝试使用and或\noalign在表格的每一行中插入一些 -code 。在大多数情况下,它可以正常工作,但如果我的命令后有-command (from ),则不行:使用此代码:colortbl\everycr\CT@everycr\rowcolorsxcolor\rowcolors

\CT@everycr{\@rowc@lors\the\everycr} 

它不会扩展\the\everycr,因此无论我输入什么\everycr都会被忽略。这是错误还是我忽略了什么?

\documentclass{article}
\usepackage{array}
\usepackage[table]{xcolor}

\begin{document}
\makeatletter
\newcommand\test{\noalign{\hrule height 0.1cm width 5cm}}
\rowcolors{0}{green}{blue}
%Works after/without \rowcolors:
\CT@everycr\expandafter{\expandafter\test\the\CT@everycr}
\begin{tabular}[t]{ll}
foo & foo\\    foo & foo\\    \multicolumn{2}{l}{blub}
\end{tabular}

\bigskip


%this fails:
\everycr\expandafter{\expandafter\test\the\everycr}
\rowcolors{0}{red}{green}
%\CT@everycr{\@rowc@lors\the\everycr}%inserted by @rowcolors

%it would work if \rowc@lors would use this:
%\CT@everycr\expandafter{\expandafter\@rowc@lors\the\everycr}%
\makeatother

\begin{tabular}[t]{ll}
foo & foo\\    foo & foo\\    \multicolumn{2}{l}{blub}
\end{tabular}
\end{document}

答案1

根据David的评论,这里有一个能够\everycr在中使用的技巧tabular

\documentclass{article}
\usepackage{array,etoolbox}
\usepackage[table]{xcolor}

\newenvironment{etabular}[1]
 {\patchcmd{\ialign}{\everycr{}}{}{}{}%
  \everycr{#1}%
  \tabular}
 {\endtabular}

\newcommand\test{\noalign{\hrule height 0.1cm width 5cm}}

\begin{document}
\rowcolors{0}{green}{blue}
\begin{etabular}{\test}[t]{ll}
foo & foo\\
foo & foo\\
\multicolumn{2}{c}{blub}
\end{etabular}
\end{document}

在此处输入图片描述

我不会全局修补\ialign;但是这会使所有嵌套表格都相同\everycr。用于\begin{etabular}{}[pos]{columns}中的嵌套表格etabular

longtable可以使用非常相似的补丁:

\makeatletter
\newenvironment{elongtable}[1]
 {\patchcmd{\LT@array}{\everycr{}}{}{}{}%
  \everycr{#1}%
  \longtable}
 {\endlongtable}
\makeatother

因为\LT@array负责说\everycr{}

相关内容