# Change color of caption inside longtabu

I can make this work just fine with longtable, but I would like to use it with longtabu for some of its features.

Here's the code

\documentclass[11pt,a4paper]{book}

\usepackage[table]{xcolor}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{caption}

\begin{document}

\begin{longtabu}{cc}
\rowcolor[gray]{.5}
\caption{test}\endlastfoot
foo & bar\\
\end{longtabu}
\end{document}


If I comment out the rowcolor line, it works fine but the caption is not properly formatted.

I'm getting the following error ! Misplaced \noalign. \caption ->\noalign

I tried enclosing it in braces, putting some \expandafter around but nothing works. And it's all the more confusing when the longtabu documentation says \caption should work the same as with longtable, since it doesn't work here.

• longtabu redefines \rowcolor. It no longer works before \multicolumn (used by \caption). Try \cellcolor inside the caption instead. – Ulrike Fischer Apr 14 '18 at 13:05
• @UlrikeFischer it seems to be working if I put it inside indeed. It gave the same error if put outside, and I didn't think of putting it inside. Thanks, if you want to write an answer I'll give you a day, if you don't I'll write one to mark it as solved. – meneldal Apr 14 '18 at 13:45

longtabu redefines \rowcolor. It no longer works before \multicolumn (used by \caption). Try \cellcolor inside the \caption instead.

\documentclass[11pt,a4paper]{book}

\usepackage[table]{xcolor}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{caption}

\begin{document}

\begin{longtabu}{cc}
\caption{\cellcolor{gray}test}\endlastfoot
foo & bar\\
\end{longtabu}
\end{document}

• good to know! (+1) – Zarko Apr 14 '18 at 15:03