1

I have a script that generates super-complicated tables, which need individual cells with coloured backgrounds. At the moment I'm using my own macro to generate the coloured cells, but I would rather use the much better macros in colortbl. However, importing the colortbl package causes my latex documents to fail with:

$ pdflatex  tbl_example.tex 
! Undefined control sequence.
<template> ...@setup \CT@row@color \CT@cell@color 
                                                  \CT@do@color \endgroup \@t...
l.23 \multicolumn{1}{c}{\multirow{2}{*}{}}&&
                                            &\multicolumn{1}{c}{} &\multicol...

?

In the MWE below, commenting out either usepackage{colortbl}, or the definition of \blankheight or the table column causes this document to compile with no errors. What have I done wrong?

\documentclass{article}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{longtable}
\usepackage{mathtools}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{xspace}

\newlength{\blankheight}%
\settototalheight{\blankheight}{%
$\begin{array}{rr}%
\scriptstyle{0} \\[-6pt]%
\scriptscriptstyle{0}%
\end{array}%
$%
}

\begin{document}

\begin{longtable}{ll@{\hspace{0cm}}ll@{\hspace{-1cm}}r@{\hspace{0cm}}r@{\hspace{0cm}}r@{\hspace{0cm}}r@{\hspace{0cm}}l@{\hspace{.3cm}}ll@{\hspace{-1cm}}r@{\hspace{0cm}}r@{\hspace{0cm}}rr@{\hspace{0cm}}r}

\multicolumn{1}{c}{\multirow{2}{*}{}}&&&\multicolumn{1}{c}{} &\multicolumn{1}{c}{Column} &\multicolumn{1}{c}{Column} &\multicolumn{1}{c}{Column} &\multicolumn{1}{c}{Column} &\multicolumn{1}{c}{Column}\\
\endhead
\hline

\end{longtable}

\end{document}
  • Could you explain the details of what you're trying to achieve, and a minimal compilable code of what you've tried? – Bernard Sep 17 '18 at 11:37
  • Thanks @Bernad, the code in the question is a minimum example of the problem I'm having, when it compiles the problem will be fixed, if that makes sense. The table headings need to be as they are in the MWE, I need to define blankheight and to import colortbl. Does that help? – snim2 Sep 17 '18 at 11:43
  • But your table has no colour command! – Bernard Sep 17 '18 at 11:48
  • unrelated but \scriptsyle doesn't take an argument so I guess they should be \scriptstyle 0 – David Carlisle Sep 17 '18 at 11:48
  • @Bernard the table doesn't use colour and doesn't use \blankheight but that is just an artefact of it being a minimal example. It does give the undefined colortbl command error if you have the definition of \blankheight and not if you do not, as it says. – David Carlisle Sep 17 '18 at 11:50
3

You can delay the setting:

\documentclass{article}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{longtable}
\usepackage{mathtools}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{xspace}

\newlength{\blankheight}%

\AtBeginDocument{%
\settototalheight{\blankheight}{%
$\begin{array}{rr}%
\scriptstyle{0} \\[-6pt]%
\scriptscriptstyle{0}%
\end{array}%
$%
}}

\begin{document}

\begin{longtable}{ll@{\hspace{0cm}}ll@{\hspace{-1cm}}r@{\hspace{0cm}}r@{\hspace{0cm}}r@{\hspace{0cm}}r@{\hspace{0cm}}l@{\hspace{.3cm}}ll@{\hspace{-1cm}}r@{\hspace{0cm}}r@{\hspace{0cm}}rr@{\hspace{0cm}}r}

\multicolumn{1}{c}{\multirow{2}{*}{}}&&&\multicolumn{1}{c}{} &\multicolumn{1}{c}{Column} &\multicolumn{1}{c}{Column} &\multicolumn{1}{c}{Column} &\multicolumn{1}{c}{Column} &\multicolumn{1}{c}{Column}\\
\endhead
\hline

\end{longtable}

\end{document}
  • That's clever! I had no idea it was even possible, thanks! – snim2 Sep 17 '18 at 11:52

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.