1

I'm trying to construct a multi-page, landscape table with variable column widths. It was working until I started to get a problem with the caption. If I try to include a short caption I get the error "Missing number, treated as zero \end{tabularx}" and "Illegal unit of measure (pt inserted) \end{tabularx}".

Below is a minimal non-working example. I'm sure it was working earlier and I'm not sure what I've done to break it.

% 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}
4

ltablex redefines \caption incorrectly, you should have used ltxtable :-)

The simplest fix is

\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}
0

\caption has to be outside of the tabularx environment but inside a float environment, such as \begin{table}...\end{table}.

Edit:

Although my answer compiles, my explanation was incorrect. See David Carlisle's answer and comment for an explanation.

\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}
  • 1
    No, ltablex defines tabularx to be longtable which defines \caption, ltablex redefines caption incorrectly. As the OP says, it works if you do not use the optional argument – David Carlisle Jul 9 '14 at 12:17
  • Thanks for pointing this out to me. I up voted your answer. – Michael S Taylor Jul 9 '14 at 12:30

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.