I try to create a multipage table that’s why I use the ltablex package and the tabularx environment. My example below is a shortened one-page table.
The table is to look like the first table below. It’s pretty fine that way. (By the way, I embedded the tabularx environment in a center environment to align the table with the regular text and the pageheadings. Is this the most elegant or best way to do it? And why is a table that is defined with the same width as the regular text not automatically aligned with the pageheadings and the regular text?)
The problem occurs when I try to add a table caption: in the second table with a caption not broad enough itself and in the third table a caption with defined width as a textline (that’s what I prefer). However, both examples are narrowing the table itself so that it is spread over many pages.
What’s the way to fix it?
(One further little question that came up when I created this example: the first table seems to have the internal counter 1 even without caption. What’s the way to avoid this?).
Thank you very much for your support!
maths-user
Code: Select all
\documentclass[a4paper,12pt]{report}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[OR]{}
\fancyhead[OL]{Text of pageheader}
\setlength\headheight{15pt}
\usepackage{ltablex}
\usepackage{booktabs}
\begin{document}
This is a text at the beginning of the document which shows the width of a line.
\begin{center}
\begin{tabularx}{\linewidth}{@{} r X @{}}
\toprule
& This is a long line containing a linebreak for demonstration of a table that has same width as regular textlines. \\
$+$ & This is a second line. \\
\midrule
$=$ & This is a preliminary sum. \\
\midrule
$=$ & This is a third line to add. \\
\midrule
$=$ & Result \\
\bottomrule
\end{tabularx}
\end{center}
\begin{center}
\begin{tabularx}{\linewidth}{@{} r X @{}}
\caption{Table just for demonstration purposes with a very very long headline} \\
\toprule
& This is a long line containing a linebreak for demonstration of a table that has same width as regular textlines. \\
$+$ & This is a second line. \\
\midrule
$=$ & This is a preliminary sum. \\
\midrule
$=$ & This is a third line to add. \\
\midrule
$=$ & Result \\
\bottomrule
\end{tabularx}
\end{center}
\setlength\LTcapwidth{\linewidth}
\begin{center}
\begin{tabularx}{\linewidth}{@{} r X @{}}
\caption{Table just for demonstration purposes with a very very long headline} \\
\toprule
& This is a long line containing a linebreak for demonstration of a table that has same width as regular textlines. \\
$+$ & This is a second line. \\
\midrule
$=$ & This is a preliminary sum. \\
\midrule
$=$ & This is a third line to add. \\
\midrule
$=$ & Result \\
\bottomrule
\end{tabularx}
\end{center}
\end{document}