# left alignment of longtable - unwanted minimal indent

I have a longtable which is a tiny bit indented, despite I have set LTleft to zero. The header line of the table "Gedichttitel .." is not aligned with the text above!

Reading other perhaps related questions did not help so far; for example, it seems that @ could be useful in this case, but I cannot understand its use nor find documenation (the documenation for the array package seems to technical for me).

The MVE is:

\documentclass{scrbook}
\KOMAoptions{paper=     %161mm:239mm, % increased size to avoid resizing
6.14in:9.21in,   %format of proof
BCOR=8mm,twoside,
titlepage=true,
DIV=13,  % textbuecher 11 % textwidth 117
fontsize=11pt,
}
\usepackage[german]{babel}

\usepackage{booktabs,array,microtype, longtable}

\setlength\LTleft{0pt}
\setlength\LTright\fill

\begin{document}

\newcommand{\dohang}{\hangindent1em\hangafter1 }

\section{Titel der Gedichte - Titels of Poems}

Da Gedichttitel manchmal im Laufe der Zeit verändert werden

\begin{longtable}{>{\everypar{\dohang}\dohang\raggedright\arraybackslash}p{0.7\textwidth}
p{0.15\textwidth}
p{0.05\textwidth}
p{0.1\textwidth}}
Gedichttitel - erste Zeile & Anzahl Zeilen & Buch  & Nummer \\\\

Abendblick vom Hochstein &  16 &   1 &   1 \\
Abschied &  17 &   1 &  56 \\
Als ich zum ersten Male diesen Narren &  14 &   1 &  30 \\
Als König Salomo beim Tempelbau &  14 &   1 &  50 \\

\end{longtable}

\end{document}


What needs to be changed to have the table exactly aligne with the text?

Add @{} before the first column definition:

\documentclass{scrbook}
\KOMAoptions{paper=     %161mm:239mm, % increased size to avoid resizing
6.14in:9.21in,   %format of proof
BCOR=8mm,twoside,
titlepage=true,
DIV=13,  % textbuecher 11 % textwidth 117
fontsize=11pt,
}
\usepackage[german]{babel}

\usepackage{booktabs,array,microtype, longtable}

\setlength\LTleft{0pt}
\setlength\LTright\fill

\begin{document}

\newcommand{\dohang}{\hangindent1em\hangafter1 }

\section{Titel der Gedichte - Titels of Poems}

Da Gedichttitel manchmal im Laufe der Zeit verändert werden

\begin{longtable}{%
@{}
>{\everypar{\dohang}\dohang\raggedright\arraybackslash}
p{0.64\textwidth}
r
r
r
@{}
}
Gedichttitel - erste Zeile & \multicolumn{1}{p{0.12\textwidth}}{Anzahl Zeilen} & Buch  & Nr. \\\\

Abendblick vom Hochstein &  16 &   1 &   1 \\
Abschied &  17 &   1 &  56 \\
Als ich zum ersten Male diesen Narren &  14 &   1 &  30 \\
Als König Salomo beim Tempelbau &  14 &   1 &  50 \\

\end{longtable}

\end{document}


• Also, add the @{} after the last column, and right align column with figures. – Sveinung Jul 11 at 11:01
• @Sveinung Is it better now? – lulu Jul 11 at 18:55
• I would also suggest removing the extra row (\) in the table header and replace it with a \midrule, and then right aligned the heading of the second column \multicolumn{1}{>{\raggedleft}p{0.12\textwidth}}{Anzahl Zeilen} – Sveinung Jul 11 at 19:47

A solution with xltabular:

\documentclass{scrbook}
\KOMAoptions{paper=     %161mm:239mm, % increased size to avoid resizing
6.14in:9.21in,   %format of proof
BCOR=8mm,twoside,
titlepage=true,
DIV=13,  % textbuecher 11 % textwidth 117
fontsize=11pt,
}
\usepackage[german]{babel}
\usepackage{booktabs,array,microtype,xltabular}
\newcommand{\dohang}{\hangindent1em\hangafter1 }

\begin{document}

\section{Titel der Gedichte - Titels of Poems}

Da Gedichttitel manchmal im Laufe der Zeit verändert werden

\begin{xltabular}{\linewidth}{@{}
>{\everypar{\dohang}\dohang\raggedright\arraybackslash}X
c c c
@{}}
Gedichttitel - erste Zeile & \shortstack{Anzahl\\Zeilen} & Buch  & Nummer \\\\
Abendblick vom Hochstein &  16 &   1 &   1 \\
Abschied &  17 &   1 &  56 \\
Als ich zum ersten Male diesen Narren &  14 &   1 &  30 \\
Als König Salomo beim Tempelbau &  14 &   1 &  50 \\
\end{xltabular}

\end{document}


• I tried the solution you propose (which looks exactly what i wanted) but get the error File xtabular.sty' not found. \usepackage. what is missing? – user855443 Jul 11 at 19:38
• @user855443 You have to ensure that you have installed required packages, xltabular, ltablex and tabularx. Also, you have to have a line \usepackage{xltabular} in you documents preamble. – Sveinung Jul 11 at 21:00
• I tried to install the xltabular from ctan. I unpacked it and copied it to ~/textmf/tex/latex/xltabular. I have now an error ! File ended while scanning use of \TX@get@body. - what could be wrong? (I have not much experience with installing from ctan). – user855443 Jul 11 at 22:05
• What operating system do you have and what TeX distribution? And did my example code works? – user187802 Jul 12 at 6:39
• i used eventually the solution from my other question and added @{} for the first column. Thank you for the explanation of tex.stackexchange.com/q/499380/161067! – user855443 Jul 15 at 9:59

Your table can also be build using the package cals. However, the \dohang command requires modification of cals left aligned cells. You need to encapsulate the text in a parbox of same width as the column width. Therefore, I have defined a new command, \colbox, where I also include the dohang and raggedright commands. The parbox's width is calculated using the same formula as I used when calculating the column width, less right and left padding (side bearing):

\newcommand{\colbox}[1]{\parbox{\dimexpr(\columnwidth)/32*19-\cals@paddingL-\cals@paddingR\relax}{\raggedright\dohang #1}}


Each of the cells in column 1 need this modification. If you disagree regarding the rules after the table header (the midrule), it is easily removed.

\documentclass{scrbook}
\KOMAoptions{paper=     %161mm:239mm, % increased size to avoid resizing
6.14in:9.21in,   %format of proof
BCOR=8mm,twoside,
titlepage=true,
DIV=13,  % textbuecher 11 % textwidth 117
fontsize=11pt,
}
\usepackage[german]{babel}

\usepackage{microtype, cals}

\let\nc=\nullcell                                                  % CALS Shortcuts
\let\sc=\spancontent

\newcommand{\dohang}{\hangindent1em\hangafter1 }
\makeatletter
\makeatother
\begin{document}

\section{Titel der Gedichte -- Titels of Poems}

Da Gedichttitel manchmal im Laufe der Zeit verändert werden
\bigskip

\begin{calstable}[l]  % Left aligned CALS tabular

% Calculate the column width
\colwidths{{\dimexpr(\columnwidth)/32*17\relax}
{\dimexpr(\columnwidth)/32*5\relax}
{\dimexpr(\columnwidth)/32*5\relax}
{\dimexpr(\columnwidth)/32*5\relax}
}

% The tabular fills the text area if sum of all columns is 32

% Set up the tabular
\makeatletter
\def\cals@framers@width{0pt}   % Outside frame rules
\def\cals@framecs@width{0pt}
\def\cals@bodyrs@width{0.6pt}  % Rule between header and tabular body
\def\cals@cs@width{0pt}             % Inside vertical rules
\def\cals@rs@width{0pt}              % Inside horizontal rules

% R1H1
\thead{%           The first row are heading and vill be repeated on every page
\brow
\lp\alignL\cell{\vfill\colbox{Gedichttitel -- erste Zeile}}\lp
\alignR\cell{\vfill Anzahl Zeilen}
\alignR\cell{\vfill Buch}
\rp\alignR\cell{\vfill Nummer}\rp
\erow
}
\tfoot{\lastrule\nointerlineskip
\strut\par}
%R2B1
\brow
\lp\alignL\cell{\colbox{Abendblick vom Hochstein}}\lp
\alignR\cell{16}
\alignR\cell{1}
\rp\alignR\cell{1}\rp
\erow
%R3B2
\brow
\lp\alignL\cell{\colbox{Abschied}}\lp
\alignR\cell{17}
\alignR\cell{1}
\rp\alignR\cell{56}\rp
\erow
%R4B3
\brow
\lp\alignL\cell{\colbox{Als ich zum ersten Male diesen Narren}}\lp
\alignR\cell{14}
\alignR\cell{1}
\rp\alignR\cell{30}\rp
\erow
%R5B4
\brow
\lp\alignL\cell{\colbox{Als König Salomo beim Tempelbau}}\lp
\alignR\cell{14}
\alignR\cell{1}
\rp\alignR\cell{50}\rp
\erow

\makeatletter
\end{calstable}\par

\end{document}
`

• would this work for the question tex.stackexchange.com/q/499380/161067 as well? – user855443 Jul 11 at 22:08
• @user855443 I have not tested, because I read that question as a different problem. I will check, but I am a little short on time (even though I am on vacation). – Sveinung Jul 12 at 8:55
• @user855443 I have an answer for your question 161067 – Sveinung Jul 12 at 21:52
• @user855443 I tested cals, but it does not update the running headers. Probably, this is a similar bug described in this answer. regarding longtable. So my preliminary answer is: No, cals does not work for question 161067! – Sveinung Jul 12 at 22:52