2

I'm using the ltablex package for creating long tables over multiple pages. For my other small tables I use the tabularx package and I noticed a formatting mistake or maybe a bug?

The table caption text of my long table created does not flush correctly with the bottomrule line.

When you run the code you will see that the caption at the bottom of the small table flushes correctly with the bottomrule line. But on the long table the caption text did not flush correctly with the bottomrule line. There the text stands out a little bit at the left side.

When i use my small table with out the \begin{table] and \end{table} Environment and put the caption inside the tabularx, the same issue as on the long table appears, so how can I get it right working on the long table. I can not use there the \begin{table] and \end{table} Environment, So is there an other way to get the caption text formatted like on my small table with the \begin{table] and \end{table} Environment?

I Added two pictures of it. The first one shows a piece of the long table and the second the small table.

enter image description here enter image description here

EDIT - Full Code

\documentclass[%
a4paper,
12pt,                   
oneside,
captions=nooneline,
parskip=half
]
{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
%\usepackage{tabularx}
\usepackage{ltablex}
\usepackage{booktabs}
\usepackage{mathptmx}% Times

\setkomafont{disposition}{\normalfont\bfseries}
\setkomafont{caption}{\fontsize{9pt}{9pt}\selectfont}

\begin{document}

\keepXColumns
\begin{table}[htbp]
\begin{tabularx}{\textwidth}{XX}
\toprule
\textbf{Column 1} & \textbf{Column 2} \\
\midrule
$R$ & 1This is an example sentence \\
$R$ & 2As well as the line before \\
$A$ & 3Also this is an example \\
$R$ & 4This is an example sentence \\
$R$ & 5As well as the line before \\
$A$ & 6Also this is an example \\
$R$ & 7This is an example sentence \\
$R$ & 8As well as the line before \\
$A$ & 9Also this is an example \\
$R$ & 10This is an example sentence \\
$R$ & 11As well as the line before \\
$A$ & 12Also this is an example \\
\bottomrule
\end{tabularx}  
\caption{Example of an table} 
\end{table}

\newpage

\keepXColumns
%\begin{table}[htbp]
\begin{tabularx}{\textwidth}{XX}
\toprule
\textbf{Column 1} & \textbf{Column 2} \\
\midrule
$R$ & 1This is an example sentence \\
$R$ & 2As well as the line before \\
$A$ & 3Also this is an example \\
$R$ & 4This is an example sentence \\
$R$ & 5As well as the line before \\
$A$ & 6Also this is an example \\
$R$ & 7This is an example sentence \\
$R$ & 8As well as the line before \\
$A$ & 9Also this is an example \\
$R$ & 10This is an example sentence \\
$R$ & 11As well as the line before \\
$A$ & 12Also this is an example \\
$R$ & 13This is an example sentence \\
$R$ & 14As well as the line before \\
$A$ & 15Also this is an example \\
$R$ & 16This is an example sentence \\
$R$ & 17As well as the line before \\
$A$ & 18Also this is an example \\
$R$ & 19This is an example sentence \\
$R$ & 20As well as the line before \\
$A$ & 21Also this is an example \\
$R$ & 22This is an example sentence \\
$R$ & 23As well as the line before \\
$A$ & 24Also this is an example \\
$R$ & 25This is an example sentence \\
$R$ & 26As well as the line before \\
$A$ & 27Also this is an example \\
$R$ & 28This is an example sentence \\
$R$ & 29As well as the line before \\
$A$ & 30Also this is an example \\
$R$ & 31This is an example sentence \\
$R$ & 32As well as the line before \\
$A$ & 33Also this is an example \\
$R$ & 34This is an example sentence \\
$R$ & 35As well as the line before \\
$A$ & 36Also this is an example \\
$R$ & 37This is an example sentence \\
$R$ & 1This is an example sentence \\
$R$ & 2As well as the line before \\
$A$ & 3Also this is an example \\
$R$ & 4This is an example sentence \\
$R$ & 5As well as the line before \\
$A$ & 6Also this is an example \\
$R$ & 7This is an example sentence \\
$R$ & 8As well as the line before \\
$A$ & 9Also this is an example \\
$R$ & 10This is an example sentence \\
$R$ & 11As well as the line before \\
$A$ & 12Also this is an example \\
$R$ & 13This is an example sentence \\
$R$ & 14As well as the line before \\
$A$ & 15Also this is an example \\
$R$ & 16This is an example sentence \\
$R$ & 17As well as the line before \\
$A$ & 18Also this is an example \\
$R$ & 19This is an example sentence \\
$R$ & 20As well as the line before \\
$A$ & 21Also this is an example \\
$R$ & 22This is an example sentence \\
$R$ & 23As well as the line before \\
$A$ & 24Also this is an example \\
$R$ & 25This is an example sentence \\
$R$ & 26As well as the line before \\
$A$ & 27Also this is an example \\
$R$ & 28This is an example sentence \\
$R$ & 29As well as the line before \\
$A$ & 30Also this is an example \\
$R$ & 31This is an example sentence \\
$R$ & 32As well as the line before \\
$A$ & 33Also this is an example \\
$R$ & 34This is an example sentence \\
$R$ & 35As well as the line before \\
$A$ & 36Also this is an example \\
$R$ & 37This is an example sentence \\
\bottomrule
\caption{Example of an table2} 
\end{tabularx}  

\end{document}
2

use

\usepackage{booktabs}
\usepackage{ltablex}
\setkomafont{disposition}{\normalfont\bfseries}
\setkomafont{caption}{\small}    
\begin{document}

\keepXColumns
\begin{tabularx}{\textwidth}{Xx}\toprule
        \textbf{Column 1} & \textbf{Column 2} \\\midrule
        $R$ & 1This is an example sentence \\
        $R$ & 2As well as the line before \\
        $A$ & 3Also this is an example \\
        $R$ & 4This is an example sentence \\
        $R$ & 5As well as the line before \\
        $A$ & 6Also this is an example \\
        $R$ & 7This is an example sentence \\
        $R$ & 8As well as the line before \\
        $A$ & 9Also this is an example \\
        $R$ & 10This is an example sentence \\
        $R$ & 11As well as the line before \\
        $A$ & 12Also this is an example \\
        \bottomrule
    \caption{Example of an table} \\
    \end{tabularx}  

\begin{tabularx}{\textwidth}{XX}
    \toprule
    \textbf{Column 1} & \textbf{Column 2} \\
    \midrule
    $R$ & 1This is an example sentence \\
    $R$ & 2As well as the line before \\
    [...]

The caption must be inside the tabularx. And do not use the environment table for the tabularx. It has its own table counter .

enter image description here

enter image description here

  • did not make any changes to it. i Edited my post and added the full code. Hope this helps. – Opa114 Feb 9 '16 at 17:36
  • see edited answer. And, by the way, the counting is correct ;-) – user2478 Feb 9 '16 at 18:08
  • you removed the \begin{tabe} tag i see. One possible solution :) But i want the padding of the caption like i have the \begin{table} tag there and the \caption tag after the \end{tabularx}. Is there a way to get this result on the long table? and which is the correct way to add a caption to tables and figures. Inside the \table and \figure tag (like you did it) or after it (like on my first table) ? :) – Opa114 Feb 9 '16 at 18:17
  • With table you get a wrong counting of the tables! It makes no sense to use it in such a environment when using ltablex! Only a default tabular environment should be inside table – user2478 Feb 9 '16 at 18:19
  • good to know, i thought the \table tag must be there every time. So i will remove the table stuff from all my other tables and have a look how it looks like then with the caption thing and will report it. – Opa114 Feb 9 '16 at 18:23
2

The solution for my problem is to use \captionsetup{margin=1pt} with the caption package. With 2pt i got the correct alignment of the caption.

thanks to Herbert!

or as alternative when using Komascript - like me - the command \setcapmargin{2pt} will do the same.

2

The caption must be incorporated in the table – just as with longtable, inside the foot specifications, if you want the caption at the bottoms of the table, or in the head soecifications to have it above the table (which is recommended).

Also, if you load ltablex, you don't have to load tabularx nor longtable since they're loaded by ltablex.

    \documentclass[a4paper]{article}%
    \usepackage{ltablex, booktabs}
    \usepackage[showframe]{geometry}
    \usepackage{caption}
    \captionsetup[table]{singlelinecheck=off, position=bottom}
     \usepackage{etoolbox}

    \begin{document}

    \keepXColumns
     \begin{table}[htbp]
    \begin{tabularx}{\linewidth}{XX}
    \toprule
    \textbf{Column 1} & \textbf{Column 2} \\
    \midrule
    $R$ & 1This is an example sentence \\
    $R$ & 2As well as the line before \\
    $A$ & 3Also this is an example \\
    $R$ & 4This is an example sentence \\
    $R$ & 5As well as the line before \\
    $A$ & 6Also this is an example \\
    $R$ & 7This is an example sentence \\
    $R$ & 8As well as the line before \\
    $A$ & 9Also this is an example \\
    $R$ & 10This is an example sentence \\
    $R$ & 11As well as the line before \\
    $A$ & 12Also this is an example \\
    \bottomrule
    \end{tabularx}
    \caption{Example of an table}
    \end{table}

    \bigskip
    {\pretocmd{\tablename}{\,}{}{}
    \begin{tabularx}{\linewidth}{XX}
    \midrule
    \caption{Example of an table}\label{xyz}
    \endfoot
    \bottomrule
    \caption{Example of an table}
    \endlastfoot
    \toprule
    \textbf{Column 1} & \textbf{Column 2} \\
    \midrule
    $R$ & 1This is an example sentence \\
    $R$ & 2As well as the line before \\
    $A$ & 3Also this is an example \\
    $R$ & 4This is an example sentence \\
    $R$ & 5As well as the line before \\
    $A$ & 6Also this is an example \\
    $R$ & 7This is an example sentence \\
    $R$ & 8As well as the line before \\
    $A$ & 9Also this is an example \\
    $R$ & 10This is an example sentence \\
    $R$ & 11As well as the line before \\
    $A$ & 12Also this is an example \\
    $R$ & 13This is an example sentence \\
    $R$ & 14As well as the line before \\
    $A$ & 15Also this is an example \\
    $R$ & 16This is an example sentence \\
    $R$ & 17As well as the line before \\
    $A$ & 18Also this is an example \\
    $R$ & 19This is an example sentence \\
    $R$ & 20As well as the line before \\
    $A$ & 21Also this is an example \\
    $R$ & 22This is an example sentence \\
    $R$ & 23As well as the line before \\
    $A$ & 24Also this is an example \\
    $R$ & 25This is an example sentence \\
    $R$ & 26As well as the line before \\
    $A$ & 27Also this is an example \\
    $R$ & 28This is an example sentence \\
    $R$ & 29As well as the line before \\
    $A$ & 30Also this is an example \\
    $R$ & 31This is an example sentence \\
    $R$ & 32As well as the line before \\
    $A$ & 33Also this is an example \\
    $R$ & 34This is an example sentence \\
    $R$ & 35As well as the line before \\
    $A$ & 36Also this is an example \\
    $R$ & 37This is an example sentence \\
    $R$ & 1This is an example sentence \\
    $R$ & 2As well as the line before \\
    $A$ & 3Also this is an example \\
    $R$ & 4This is an example sentence \\
    $R$ & 5As well as the line before \\
    $A$ & 6Also this is an example \\
    $R$ & 7This is an example sentence \\
    $R$ & 8As well as the line before \\
    $A$ & 9Also this is an example \\
    $R$ & 10This is an example sentence \\
    $R$ & 11As well as the line before \\
    $A$ & 12Also this is an example \\
    $R$ & 13This is an example sentence \\
    $R$ & 14As well as the line before \\
    $A$ & 15Also this is an example \\
    $R$ & 16This is an example sentence \\
    $R$ & 17As well as the line before \\
    $A$ & 18Also this is an example \\
    $R$ & 19This is an example sentence \\
    $R$ & 20As well as the line before \\
    $A$ & 21Also this is an example \\
    $R$ & 22This is an example sentence \\
    $R$ & 23As well as the line before \\
    $A$ & 24Also this is an example \\
    $R$ & 25This is an example sentence \\
    $R$ & 26As well as the line before \\
    $A$ & 27Also this is an example \\
    $R$ & 28This is an example sentence \\
    $R$ & 29As well as the line before \\
    $A$ & 30Also this is an example \\
    $R$ & 31This is an example sentence \\
    $R$ & 32As well as the line before \\
    $A$ & 33Also this is an example \\
    $R$ & 34This is an example sentence \\
    $R$ & 35As well as the line before \\
    $A$ & 36Also this is an example \\
    $R$ & 37This is an example sentence
    \end{tabularx}}

    \end{document} 

enter image description here enter image description here

  • as you can see on your own screenshots, the caption of the long table is to wide left aligned. I want it like on the small table. it should be flush with the bottomline. – Opa114 Feb 9 '16 at 17:59
  • I'm afraid I don't understand what you mean. To me, it is like in your post. Could you explain in more details? – Bernard Feb 9 '16 at 18:07
  • i don't want it like on my post. I want the caption of the long table to be aligned with the bottomrule line of the table. In your and my screenshost you can see that on the small table caption flushes in one line with the bottomrule line but on the long table the caption flushes not correctly with the bottomrule line. The "T" of "Table 3: Example of an table" is some milimeters to wide left; on the small table it matches correctly. The "T" on you images goes out of the box of the long table screenshot, in the small table screenshots not - can you see it? And i want it like on the small table. – Opa114 Feb 9 '16 at 18:13
  • It seems to be a bug, not sure whether it's longtable or ltablex. I added a work-around with etoolbox, just before the long table (\pretocmd{tablename]·). – Bernard Feb 10 '16 at 1:41
  • yes did fix it, too. Is there a way to make apply the command global for all tables? – Opa114 Feb 10 '16 at 10:59

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.