1

I'm trying to use bicaption for longtable, but I get this error:

Misplaced \noalign. ...tion{example}{A simple longtable example}

Here is an example:

\documentclass[UTF-8]{ctexart}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{caption}
\usepackage{bicaption}
\captionsetup[table][bi-second]{name=Table.}

\begin{document} \begin{longtable}{|c|c|c|c|} \bicaption{example}{A simple longtable example}\label{tab:longtable}\ \hline \textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \ \hline \endfirsthead \multicolumn{4}{c}% {\tablename\ \thetable\ -- \textit{Continued from previous page}} \ \hline \textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \ \hline \endhead \hline \multicolumn{4}{r}{\textit{Continued on next page}} \ \endfoot \hline \endlastfoot 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ \end{longtable} \end{document}

How can I do something to use bicaption in longtable without any errors? Thanks for your replying!

LJ GONG
  • 21

2 Answers2

1

This places \bicaption into a savebox and uses the savebox inside longtable using \multicolumn.

See also how to find longtable width

\documentclass[UTF-8]{ctexart}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{caption}
\usepackage{bicaption}
\captionsetup[table][bi-second]{name=Table.}
\makeatletter
\newcommand{\setcaptype}[1]{\def\@captype{#1}\ignorespaces}
\makeatother

\begin{document} \setbox0=\vbox{\hsize=0.5\textwidth% must be less wide than the longtable, but wider than the caption. \setcaptype{table}% \bicaption{example}{A simple longtable example}\label{tab:longtable} \addtocounter{table}{-1}}% \begin{longtable}{|c|c|c|c|} \multicolumn{4}{c}{\usebox0}\ \hline \textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \ \hline \endfirsthead \multicolumn{4}{c}% {\tablename\ \thetable\ -- \textit{Continued from previous page}} \ \hline \textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \ \hline \endhead \hline \multicolumn{4}{r}{\textit{Continued on next page}} \ \endfoot \hline \endlastfoot 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ 1 & 2 & 3 & 4 \ \end{longtable} \end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
1

This was a bug in the caption package which seems to be fixed: https://gitlab.com/axelsommerfeldt/caption/-/issues/138