\documentclass[letterpaper]{article}
\usepackage{tabu}
\usepackage[table]{xcolor}
\begin{document}
\begin{tabu} to 0.2\textwidth{XXX}
\cellcolor{blue!25} A & \cellcolor{red!25} B & \cellcolor{blue!25} C \\[-1pt]\tabucline[1pt blue]{1-1}\tabucline[1pt green]{3-3}
\cellcolor{green!25} D & \cellcolor{red!25} E & \cellcolor{green!25} F
\end{tabu}
\end{document}
答案1
LaTeXtabu
环境是使用\halign
TeX 原语实现的,因此\noalign
原语可以工作。在宏\noalign{\vskip-1pt}
的第一次和第二次使用之间使用\tabucline
。
它看起来像在 C++ 源代码中使用汇编代码,但它可以工作。
也许有人不喜欢这种 TeX 基本格式和 LaTeX 的混合。纯 pdfTeX 解决方案(不含 LaTeX)如下:
\def\Black{\pdfliteral{0 g 0 G}}
\def\defcolor#1#2{\def#1{\pdfliteral{#2 rg #2 RG}}}
\defcolor\lBlue {.66 .66 1}
\defcolor\lRed {1 .66 .66}
\defcolor\lGreen {.66 1 .66}
\defcolor\Blue {0 0 1}
\defcolor\Green {0 1 0}
\def\tab#1#2#3#4#5#6{\par
\hbox to\tabwidth{\rlap{\hbox to\tabwidth{#1\dorule#3\dorule#5\dorule}}%
\Black\rlap{ #2}\hfil\rlap{ #4}\hfil\rlap{ #6}\hfil}
\nointerlineskip}
\def\dorule{\leaders\vrule height10pt depth5pt\hfil}
\def\doruleA{\leaders\vrule height1pt\hfil}
\def\itab#1#2#3{\hbox to\tabwidth{#1\doruleA#2\doruleA#3\doruleA\Black}
\nointerlineskip}
\def\tabwidth{0.2\hsize}
\tab \lBlue {A} \lRed{B} \lBlue {C}
\itab \Blue \lRed \Green
\tab \lGreen{D} \lRed{E} \lGreen{F}
\bye
答案2
我尝试添加一个新的彩色行,但不幸的是,我只tabu
为行添加了垂直空间。然后我得到了这个没有包的不太优雅的技巧tabu
:
\documentclass[letterpaper]{article}
\usepackage[table]{xcolor}
\usepackage{colortbl}
\begin{document}
\begin{tabular}{ccc}
\cellcolor{blue!25}A & \cellcolor{red!25}B & \cellcolor{blue!25} C\\
\vspace{-3.8mm}\cellcolor{blue} & \cellcolor{red!25} & \cellcolor{green} \\
\cellcolor{green!25} D & \cellcolor{red!25}E & \cellcolor{green!25} F
\end{tabular}
\end{document}