Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm writing my thesis with the document class scrbook from koma-script and want to use the package ltablex (= longtable + tabularx) for setting long tables with automatic page break calculation.

Now, I'm struggling with two problems:

  1. Why is the caption a bit longer than \linewidth (please see minimal document below)?
  2. Why do I get an latex error when I use \caption[short]{long caption} with ltxtable?

Thank you very much for your help in advance!

% Please find below a minimal latex document, that shows the problem
%
\RequirePackage[l2tabu,orthodox]{nag}
\documentclass[pagesize=pdftex,ngerman,english,paper=a5,fontsize=10pt,%
               DIV=calc,BCOR=4mm,twoside,headinclude,footinclude,open=right,%
               parskip=half,numbers=noenddot,headings=small]{scrbook}

% Geometry
\usepackage[showframe]{geometry} % showframes for debugging reasons

% Input and font encoding, Babel
\usepackage{cmap}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman,english]{babel}
\usepackage{lmodern,textcomp}

% Tables
\usepackage[NewCommands]{ragged2e}
\usepackage{array}
\usepackage{tabularx,longtable,ltablex}
\usepackage{booktabs}

% Misc. packages
\usepackage[pdftex,final]{graphicx}
\usepackage{amsmath,bm}
\usepackage[babel,final]{microtype}
\usepackage{fixltx2e,ellipsis}
\usepackage{subfigure}
\usepackage{acronym}

% Hyperref
\usepackage[pdftex=true,pdfpagemode=UseNone,pdfpagelayout=TwoPageRight,%
            pdfcenterwindow=true,pdffitwindow=true,colorlinks=true]{hyperref}

% Note: Not all of the above packages are used in this minimal example. They
%       are included for debug reasosn, because they are used in the final
%       document.

% ----------------------------------------------------------------------------

\begin{document}
%\listoftables

\chapter{First Chapter}
\begin{tabularx}{\linewidth}{XXXX}

%This is the caption of the table...
\caption{Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.} \\ % This works.

%\caption[Lorem ipsum]{Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.} \\ % This doesn't works!


%This is the header for the first page of the table...
  \toprule
  \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} \\
  \midrule
\endfirsthead

%This is the header for the remaining page(s) of the table...
  \multicolumn{4}{l}{{\tablename} \thetable{}: \ldots Continued from previous page} \\
  \toprule
  \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} \\
  \midrule
\endhead

%This is the footer for all pages except the last page of the table...
  \midrule
  \multicolumn{4}{r}{Continued on next page\ldots} \\
  \midrule
\endfoot

%This is the footer for the last page of the table...
  \bottomrule
\endlastfoot

%Now the data...
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{tabularx}

\end{document}
share|improve this question
3  
"Not all of the above packages are used in this minimal example" => Therefore it isn't a minimal example. The purpose of a minimal example is not showing what packages are used in the main document, its purpose is to limit the amount of packages to examine what packages (and macros) are needed to reproduce the problem, so you get an idea what packages and/or macros are causing the problem. (I.e. building a minimal example is the very first step for examination of a texnical problem.) –  Axel Sommerfeldt Dec 30 '10 at 12:21

1 Answer 1

Answer 1: This seems to be a problem with the longtable package:

\documentclass{scrbook}

% Geometry
\usepackage[showframe]{geometry} % showframes for debugging reasons

% Tables
\usepackage{longtable,booktabs}

\begin{document}
%\listoftables

\chapter{First Chapter}
\begin{longtable}{llll}

%This is the caption of the table...
\caption{Lorem ipsum dolor sit amet, consetetur sadipscing eltr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.} \\

%This is the header for the first page of the table...
  \toprule
  \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} \\
  \midrule
\endhead

%This is the footer for all pages except the last page of the table...
  \midrule
  \multicolumn{4}{r}{Continued on next page\ldots} \\
  \midrule
\endfoot

%This is the footer for the last page of the table...
  \bottomrule
\endlastfoot

%Now the data...
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
\end{longtable}

\end{document}

Will do further examination on this week-end...

Addendum: This is because of the extra space between \caption{...} and \\. The longtable does not ignore it (design flaw), so you have to remove it to get a proper alignment.

Answer 2: The ltablex package redefines \caption in a way which does not support using the optional argument. So it's a bug in ltablex.

Addendum: This bug could be fixed by replacing \def\caption{\\} with \renewcommand\caption[1][]{\\} inside ltablex.sty. Either do a copy of ltablex.sty to myltablex.sty and make the change in myltablex.sty, or use this very dirty patch in the preamble of your document:

\makeatletter
\begingroup
\long\def\x#1\TX@verb#2\edef#3\endhead#4\@nil{%
  \endgroup
  \def\TX@endtabularx{%
    #1\TX@verb
    \def\@elt####1{\global\value{####1}\the\value{####1}\relax}%
    \edef#3\endhead
    \renewcommand\caption[1][]{\\}%
    #4}%
}
\expandafter\x\TX@endtabularx\@nil
\makeatother

(I'm sure a TeX wizard can advance this one.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.