0

I've written a script to diff latex files and then produce markup by adding green or red tcolorboxes around most types of content and special handle any cases where that doesn't work well (like table rows), which works great generally. Note: using latex diff wasn't practical for the content in the document I'm working on.

I've hit an issue with tables produced using the longtable environment (tabular and tabularx are fine). When the caption has been changed it is inserted into a tcolorbox, however I get the following error when trying to compile it using xelatex:

\caption ->\noalign 
                    \bgroup \@ifnextchar [{\egroup \LT@c@ption \@firstofone ..

tabularx example (works)

\begin{table}[H]
\begin{tcolorbox}[on line,arc=0pt,outer arc=0pt,colback=green!10!white,colframe=green!50!black, boxsep=0pt,left=1pt,right=1pt,top=2pt,bottom=2pt, boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, rightrule=0pt, leftrule=0pt]\caption{my caption}\end{tcolorbox}
\label{table:mycaption}
\begin{tabular}{|l|l|}
\hline
\rowcolor{table}
\textbf{Value} & \textbf{Description} \\ \hline
abc & waffle here \\ \hline
\rowcolor{green!10!white}"def" & new waffle here \\ \hline
\end{tabular}
\end{table}

longtable example (doesn't work)

\begin{longtable}{|l|l|l|p{2.77in}|}
\begin{tcolorbox}[on line,arc=0pt,outer arc=0pt,colback=green!10!white,colframe=green!50!black, boxsep=0pt,left=1pt,right=1pt,top=2pt,bottom=2pt, boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, rightrule=0pt, leftrule=0pt]\caption{my caption}\end{tcolorbox}
\label{table:mycaption}
\endfirsthead
\endhead
\hline
\rowcolor{table}
\textbf{Value} & \textbf{Description} \\ \hline
abc & waffle here \\ \hline
\rowcolor{green!10!white}"def" & new waffle here \\ \hline
\end{longtable}
  • Off topic, but is \caption{my caption} a referece to the Dead Poets Society? – John Kormylo May 2 at 15:41
0

You have to add double backslash after label, it is a special "quirk" of longtable.

Like so:

\begin{longtable}{|l|l|l|p{2.77in}|}
\begin{tcolorbox}[on line,arc=0pt,outer arc=0pt,colback=green!10!white,colframe=green!50!black, boxsep=0pt,left=1pt,right=1pt,top=2pt,bottom=2pt, boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, rightrule=0pt, leftrule=0pt]\caption{my caption}\end{tcolorbox}
\label{table:mycaption}\\
\endfirsthead
\endhead
\hline
\rowcolor{table}
\textbf{Value} & \textbf{Description} \\ \hline
abc & waffle here \\ \hline
\rowcolor{green!10!white}"def" & new waffle here \\ \hline
\end{longtable}

Please, next time make your code compilable by itself, meaning also with package loading, documentclass and begin/end document.

| improve this answer | |
0

Note that longtable uses a custom \caption, which can be avoided by expanding the caption outside the longtable.

It is possible to obtain the width of the longtable from the aux file via \csname LT@\roman{LT@tables}\endcsname, but it isn't easy (see How to obtain width of longtable?).

\documentclass{article}
\usepackage{longtable}
\usepackage{tcolorbox}
\usepackage{caption}
\usepackage{showframe}

\newsavebox{\tempbox}

\begin{document}
\savebox{\tempbox}{%\abovecaptionskip=0pt% reversed for tables
\begin{tcolorbox}[on line,arc=0pt,outer arc=0pt,colback=green!10!white,colframe=green!50!black, boxsep=0pt,left=1pt,right=1pt,top=2pt,bottom=2pt, boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, rightrule=0pt, leftrule=0pt]
  \captionof{table}{my caption}% 
  \label{table:mycaption}%
\end{tcolorbox}%
}%
\begin{longtable}{|l|l|l|p{2.77in}|}
\noalign{\noindent\box\tempbox}% avoid duplicate labels
\endfirsthead
\endhead
\hline
%\rowcolor{table}% ?????
\textbf{Value} & \textbf{Description} \\ \hline
abc & waffle here \\ \hline
%\rowcolor{green!10!white}
"def" & new waffle here \\ \hline
\end{longtable}

\end{document}
| improve this answer | |

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.