# Conflict between colortbl and \hrulefill

I define a new environment \CCG that takes two arguments (i.e. above and below texts) and an optional suffix. I use \hrulefill to make sure that horizontal line fills the space before a suffix.

This solution seems to be messed up by colortbl package (e.g. when I use coloring a cell, for example).

How I can use colortbl and still have the structure similar to CCG? Manually encoding \hrule size is not a solution as CCG structures can be nested and length of texts can also vary.

MWE2 with nested structures:

\documentclass[10pt,a4paper]{article}

\usepackage{colortbl}

\newcommand{\CCG}[3][]{
\begin{tabular}[t]{@{\hspace{-3pt}}c@{\hspace{-3pt}}}
#2\\[-7pt]
\hrulefill\raisebox{-2.5pt}{\footnotesize{#1}}\\
\begin{tabular}[t]{@{}c@{}}
#3
\end{tabular}
\end{tabular}
}

\begin{document}

\CCG[suffix]{\cellcolor{green}above text}{below text}
%\hspace{2cm}
%\CCG[suffix]{above text}{below text}
\vspace{5mm}

\CCG[$<$]{
\CCG[$>$]{%
\CCG{some}{$NP/N$}
\CCG{man}{$N$}}
{$NP$}
\CCG{run}{$S\backslash NP$}}
{$S$}

\end{document}

• Since \CCG content can be more arbitrary, could you provide some examples of these? How should the nesting preserve colour changes if nesting occurs in the "above text" part?
– Werner
Sep 1, 2015 at 0:37
• Sorry for unclear text. Let's say I just want to use colortbl with other tables not related to CCG. And forget about nesting. The two texts should be center aligned and a horizontal line+suffix filling the area between them (suffix is often one lettered). Sep 1, 2015 at 0:42

The comments in colortbl.dtx suggest that the author of the package, David Carlisle, deliberately changed first-order infinite glue (fil) around cells with second-order one (fill), in order “to dissuade people from putting stretch glue in table entries”. You can easily see this glue with \showlists.

A possible, but horrible, workaround could be the following:

\documentclass[10pt,a4paper]{article}

\usepackage{colortbl}

\newcommand{\CCG}[3][]{
\begin{tabular}[t]{@{\hspace{-3pt}}c@{\hspace{-3pt}}}
#2\\[-7pt]
\leavevmode \leaders \hrule \hskip 0pt plus 1filll \kern 0pt % <<< change
\raisebox{-2.5pt}{\footnotesize{#1}}\\
\begin{tabular}[t]{@{}c@{}}
#3
\end{tabular}
\end{tabular}
}

\begin{document}

\CCG[suffix]{\cellcolor{green}above text}{below text}
\hspace{2cm}
\CCG[suffix]{above text}{below text}
% \showboxdepth = 10
% \showlists
\vspace{5mm}

\CCG[$<$]{
\CCG[$>$]{%
\CCG{some}{$NP/N$}
\CCG{man}{$N$}}
{$NP$}
\CCG{run}{$S\backslash NP$}}
{$S$}

\end{document}


but I cannot accept any responsibility for anything this could break down inside the colortbl package! ;-)

Edit

Btw, here is the output:

I did the new environment with calc package for calculating widths of texts and then setting a size of \rule according to them.

Though the lines are nicely drawn (what I needed), cell coloring is bit messed. But it works well outside the new environment.

It would be helpful to know why the colors go outside the boundaries in the new environment.

\documentclass[10pt,a4paper]{article}

\usepackage{colortbl}
\usepackage{calc}

\newcommand{\newccg}[3][]{%
\begin{tabular}[t]{@{\kern-1pt}c@{\kern-1pt}}
#2
\\[-1mm]
\rule[2.3pt]{\maxof{\widthof{#2}}{\widthof{#3}}-\widthof{#1}}{1pt}#1
\\[-1mm]
#3
\end{tabular}
}

\begin{document}

\newccg[$>>>$]{AA}{BBBBB}
~
\newccg[$<$]{CCCCCCCC}{DD}
~
\newccg[$<$]{
\newccg[$>$]{%
\newccg{\cellcolor{green}some}{$NP/N$}
\newccg{man}{$N$}}
{$NP$}
\newccg{run}{\cellcolor{red}$S\backslash NP$}}
{$S$}

\begin{tabular}{c | c}\hline
A & \cellcolor{red}A\\\hline
\cellcolor{green}C & D\\\hline
\end{tabular}

\end{document}