# two questions about longtable package

1. Why in \longtable package for end of line used two commands - @tabularcr and \lt@tabularcr. Because for my package \ command should use once for one line. Yes, I cannot redefine \lt@tabularcr command, and left only @tabularcr command, but it is very interesting for me to understand why for new line two commands calls. 2. How can I redefine \caption command for longtable. When I try to do it, I get an error:

! Extra alignment tab has been changed to \cr.


Why does this happen? Thanks everybody very much for the help.

\documentclass{article}
\usepackage{longtable}
\ExplSyntaxOn
\makeatletter
\cs_new_eq:NN\LTX@LT@tabularcr \LT@tabularcr
\cs_new_eq:NN\original@caption \caption
\cs_new_eq:NN\LTX@tabularcr \@tabularcr
\RenewDocumentCommand \LT@tabularcr{s o}{
\use:x{
\exp_not:N\LTX@LT@tabularcr
\IfBooleanT {#1} { * } \IfValueT {#2} { [#2]}
}
\message{new~line}
}
\RenewDocumentCommand \@tabularcr{s o}{
\use:x{
\exp_not:N\LTX@tabularcr
\IfBooleanT {#1} { * } \IfValueT {#2} { [#2]}
}
\message{new~tabularcr~line}
}
\RenewDocumentCommand\caption{s o m}{
\message{new~caption}
\use:x{
\exp_not:N\orig@caption
\IfBooleanT {#1} { * } \IfValueT {#2} { [#2]}
}
}
\makeatother
\ExplSyntaxOff
\pagestyle{empty}
\begin{document}
\begin{longtable}{ccc}
\caption{test of long tables}
a&b&c\\
d&e&f\\
g&h&i
\end{longtable}
\end{document}

• \caption acts like \multicolumn{..}{....} so must expand to the tex primitive column span, you can not have \message{ or even \relax or {} or anything non expandable at the start. – David Carlisle Dec 23 '20 at 20:47
• similarly you can not have \message{new~tabularcr~line} at that point in your \\  redefinition as that will stop \multicolumn, or \hline working following \ as they must be teh first thing in the row. – David Carlisle Dec 23 '20 at 21:42
• sorry I don't understand your question about (lt)@tabularcr as I say one is the original version from tabular and isn't defined in the longtable package at all, the other is an extended version from longtable that allows page breaking but calls the original internally. – David Carlisle Dec 23 '20 at 22:06
• your caption command is looking for an optional argument, that is not expandable, so that breaks column spanning, – David Carlisle Dec 23 '20 at 22:07
• you should have known not to add \message and that \@tabularcr comes from tabular as you had a long answer about exactly those things here tex.stackexchange.com/a/570114/1090 – David Carlisle Dec 24 '20 at 0:11