I'm trying to make a table that looks like: desired table So far, I have this:


    \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

However, this results in the following table: what it looks like now How can I move the green line up and eliminate the whitespace between the rows?

  • Is mandatory use of tabu package for this table? – juanuni Jul 30 '17 at 6:04

LaTeX tabu environment is implemented using \halign TeX primitive, so \noalign primitive works. Use \noalign{\vskip-1pt} between first and second usage of \tabucline macro.

It looks like using assembler code inside C++ source code, but it works.

Maybe somebody doesn't like such mix of TeX primitives and LaTeX. The pure pdfTeX solution (without LaTeX) is here:

\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}

   \hbox to\tabwidth{\rlap{\hbox to\tabwidth{#1\dorule#3\dorule#5\dorule}}%
      \Black\rlap{ #2}\hfil\rlap{ #4}\hfil\rlap{ #6}\hfil}
\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}

\tab  \lBlue {A} \lRed{B} \lBlue {C}
\itab \Blue      \lRed    \Green 
\tab  \lGreen{D} \lRed{E} \lGreen{F}

  • Thanks! I'm currently generating these tables with a script anyways so \noalign seems to be a bit easier to use. – DoctorSelar Jul 30 '17 at 15:26
  • Thank you so much! I was searching for this!!! – JenyaKh Nov 11 '19 at 20:09

I try this adding a new colored row but unfortunately I only get tabu add vertical space to rows. Then I get this non-ellegant trick without tabu package:



\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


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.