Tabularx 和短标题导致错误

Tabularx 和短标题导致错误

我正在尝试构建一个多页横向表格,其列宽可变。它一直运行良好,直到我开始遇到标题问题。如果我尝试添加一个简短的标题,我会收到错误“缺少数字,视为零 \end{tabularx}”和“非法测量单位(插入 pt) \end{tabularx}”。

下面是一个最小的非工作示例。我确信它之前是工作的,但我不确定我做了什么让它坏了。

% New template
\documentclass[a4paper,11pt,twoside]{article}

%\usepackage{rotating}
\usepackage{tabularx} % For paragraph cells in tables
\usepackage{ltablex} % allows tabularx over multiple pages. May need to be compiled a couple of times. 
\usepackage{lscape}
\usepackage{booktabs}

\newcolumntype{b}{>{\footnotesize}X}
\newcolumntype{s}{>{\footnotesize\hsize=.3\hsize}X}

\begin{document}
\begin{landscape}
%%%%%%%%%%%%%%
% May need following command to avoid problems with other tables
%\keepXColumns
%%%%%%%%%%%%%%
\begin{tabularx}{\linewidth}{ssssbbbbb}
\toprule
col1 & col2 & col3 & col4 & col5 & col6 & col7 & col8 & col9 \\
\midrule
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\
\bottomrule
\caption[short caption]{long caption {\label{lit_review}}}
\end{tabularx}
\end{landscape}
\end{document}

答案1

ltablex重新定义\caption不正确,你应该使用 ltxtable:-)

最简单的解决方法是

\documentclass[a4paper,11pt,twoside]{article}

%\usepackage{rotating}
\usepackage{tabularx} % For paragraph cells in tables
\usepackage{ltablex} % allows tabularx over multiple pages. May need to be compiled a couple of times. 
\usepackage{lscape}
\usepackage{booktabs}

\newcolumntype{b}{>{\footnotesize}X}
\newcolumntype{s}{>{\footnotesize\hsize=.3\hsize}X}


\makeatletter

\begin{document}
\begin{landscape}

%%%%%%%%%%%%%%
% May need following command to avoid problems with other tables
%\keepXColumns
%%%%%%%%%%%%%%
\begin{tabularx}{\linewidth}{ssssbbbbb}
\toprule
col1 & col2 & col3 & col4 & col5 & col6 & col7 & col8 & col9 \\
\midrule
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\
\bottomrule
\ifx\caption\savecaption
\caption[short caption]{long caption {\label{lit_review}}}
\fi
\end{tabularx}
\end{landscape}
\end{document}

答案2

\caption必须位于tabularx环境之外但在浮动环境之内,例如\begin{table}...\end{table}

编辑

虽然我的答案是可以编译的,但我的解释是错误的。请参阅 David Carlisle 的回答和评论以获取解释。

\documentclass[a4paper,11pt,twoside]{article}

%\usepackage{rotating}
\usepackage{tabularx} % For paragraph cells in tables
\usepackage{ltablex} % allows tabularx over multiple pages. May need to be compiled a couple of times. 
\usepackage{lscape}
\usepackage{booktabs}

\newcolumntype{b}{>{\footnotesize}X}
\newcolumntype{s}{>{\footnotesize\hsize=.3\hsize}X}

\begin{document}
\begin{landscape}
%%%%%%%%%%%%%%
% May need following command to avoid problems with other tables
%\keepXColumns
%%%%%%%%%%%%%%
\begin{table}
\begin{tabularx}{\linewidth}{ssssbbbbb}
\toprule
col1 & col2 & col3 & col4 & col5 & col6 & col7 & col8 & col9 \\
\midrule
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\
\bottomrule
\end{tabularx}
\caption[short caption]{long caption {\label{lit_review}}}
\end{table}
\end{landscape}
\end{document}

相关内容