Graphics, Figures & Tablesltablex | Caption of a multi-page Table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
maths-user
Posts: 6
Joined: Fri Aug 26, 2011 1:44 pm

ltablex | Caption of a multi-page Table

Post by maths-user »

I have got a problem with caption in combination with tabularx.
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}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

maths-user
Posts: 6
Joined: Fri Aug 26, 2011 1:44 pm

Re: ltablex | Caption of a multi-page Table

Post by maths-user »

Is there anybody who has got a solution for this problem?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

ltablex | Caption of a multi-page Table

Post by localghost »

I can't tell you what is going wrong. Perhaps a bug in the ltablex package. But I can offer a solution that uses the combination of the packages longtable and tabu.

Code: Select all

\documentclass[12pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage{booktabs,longtable,tabu}

\begin{document}
  This is a text at the beginning of the document which shows the width of a line.

  \begin{longtabu} to \linewidth {@{}rX@{}}\toprule
    & This is a long line containing a line break for demonstration of a table that has same width as regular text lines. \\
    $+$ & This is a second line. \\ \midrule
    $=$ & This is a preliminary sum. \\ \midrule
    $=$ & This is a third line to add. \\ \midrule
    $=$ & Result \\ \bottomrule
  \end{longtabu}

  \begin{longtabu} to \linewidth {@{}rX@{}}
    \caption{Table just for demonstration purposes with a very very long headline} \\ \toprule
    & This is a long line containing a line break for demonstration of a table that has same width as regular text lines. \\
    $+$ & This is a second line. \\ \midrule
    $=$ & This is a preliminary sum. \\ \midrule
    $=$ & This is a third line to add. \\ \midrule
    $=$ & Result \\ \bottomrule
  \end{longtabu}

  \setlength{\LTcapwidth}{\linewidth}
  \begin{longtabu} to \linewidth {@{}rX@{}}
    \caption{Table just for demonstration purposes with a very very long headline} \\ \toprule
    & This is a long line containing a line break for demonstration of a table that has same width as regular text lines. \\
    $+$ & This is a second line. \\ \midrule
    $=$ & This is a preliminary sum. \\ \midrule
    $=$ & This is a third line to add. \\ \midrule
    $=$ & Result \\ \bottomrule
  \end{longtabu}
\end{document}
For further details please refer to the manuals of the involved packages.
maths-user wrote:(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?).
As far as I know the »longtable« environment increments the table counter even without a caption, and so does the »tabularx« environment from ltablex. And the »longtabu« environment will do so, too. The longtable manual should tell you the details.


Thorsten
Post Reply