2

I created a table in the appendix of my thesis with the tabularx-package and afterwards I realized it is way too long and does not jump over to the next page. I tried to use ltxtable to make it jump over to the next page and now spended a whole afternoon but could not make it work... I installed this in my Master-file:

\counterwithout{table}{chapter}
\usepackage{caption} 
\usepackage{ltxtable}
\usepackage{filecontents} 
\usepackage{longtable} 
\usepackage{tabularx}

And this is the code for my table:

\begin{filecontents}{\TabelleA1.tex}
\begin{longtable}{ccccccccccccccc}
\renewcommand{\thetable}{\Alph{table}} % Setting table number output to letters 
\setcounter{table}{0}
\caption[This is my table]{\textit{In reality it has 74 rows}}
\toprule
ID& Age & Sex & Group & WST & IQ & Code &    AQ  & ADOS Kommunikation & ADOS Sozial & ADOS Total & ADI-R Sozial & ADI-R Kommunikation & ADI-R Verhalten & ADI-R Beginn\\
\midrule
\endfirsthead
1&29&w&ASS&21&85&AS& 40  &5&7&12    &   14&10&2&3 \\
2&26&m&ASS&27&93&FA& --- &5&9&14&   23&16&5&3\\
3&31&m&ASS&31&101&FA& 29 &4&5&9&        30&16&11&4\\
4&25&w&ASS&34&110&AS&35&3&8&    11& 21& 13& 6&  2\\
5&35&m&ASS&33&107&AS&43&2&5&    7&  17& 4&  4&and many more lines\\
\bottomrule
\endlastfoot
\vspace{2mm}
{\raggedright \footnotesize{\textit{Note.} Abbr = Explanation.}\par}
\end{longtable}
\end{filecontents}
\LTXtable{\textwidth}{\jobname-Tabelle1.tex}

The error message i get:

! Undefined control sequence.
<argument> \TabelleA
1.tex
l.4 \begin{filecontents}{\TabelleA1.tex}

Is the filecontents package not installed? If I delete the lines relating to file content, latex is running "Process is started" but never stops and never creates a pdf... Can I not use \toprule, \midrule etc. in this environment? Or is the problem the 15 columns? I am desperate, would be great if you could help!

  • Welcome to TeX.SX! Could you please add a minimal working example (MWE) to your question that allows others to reproduce the issue you describe? – leandriis Jul 29 at 20:15
  • Also, are you bound to use the ltxtable package or could you switch to an alternative such as xltabular? – leandriis Jul 29 at 20:16
  • 1
    In addition to the stray > caracters in your code (See >\usepackage{caption} ) there is a \\ missing after your caption command. Also, as you only used c type columns (and no X type columns that yould be typical for tabularx) why do you need an environment that combines the features of longtable and tabularx? – leandriis Jul 29 at 20:21
  • 1
    \renewcommand{\thetable}{\Alph{table}} should also be used outside of the longtable environment. – leandriis Jul 29 at 20:22
1

Here is my suggestion using a simple longtable in combination with the threeparttablex package for the table notes. I have also moved some repeated information from the column headers into a common header and introduced some abbreviations. In order to make the table fit to the textwidth (of a standard report with the geometry package loaded). I have also reduced the font size to \small and changed the horizontal white space between adjacent columns (tabcolsep). Lastly, I have used the textfont=it option of the caption package instead of manually setting the text of the caption to use italics.

enter image description here

\documentclass{report}
\usepackage{geometry}
\usepackage[textfont=it]{caption} 
\usepackage{booktabs}
\usepackage{longtable}
\usepackage[flushleft, para, referable]{threeparttablex}

\begin{document}

\renewcommand{\thetable}{\Alph{table}} 
\begin{ThreePartTable}
\begin{TableNotes}
\note Abbr = Explanation.
\end{TableNotes}
\small
\setlength{\tabcolsep}{3pt}
\begin{longtable}{ccccccccccccccc}
\caption[This is my table]{In reality it has 74 rows}\\
\toprule
& & & & & & & &  \multicolumn{3}{c}{ADOS} & \multicolumn{4}{c}{ADI-R}\\
\cmidrule(r){9-11} \cmidrule(l){12-15}
ID& Age & Sex & Group & WST & IQ & Code &    AQ  &  Kommun. &  Sozial &  Total & Sozial &  Kommun. &  Verh. &  Beginn\\
\midrule
\endfirsthead
\bottomrule
\insertTableNotes\\
\endlastfoot
1&29&w&ASS&21&85&AS& 40  &5&7&12    &   14&10&2&3 \\
2&26&m&ASS&27&93&FA& --- &5&9&14&   23&16&5&3\\
3&31&m&ASS&31&101&FA& 29 &4&5&9&        30&16&11&4\\
4&25&w&ASS&34&110&AS&35&3&8&    11& 21& 13& 6&  2\\
5&35&m&ASS&33&107&AS&43&2&5&    7&  17& 4&  4& \\
\end{longtable}
\end{ThreePartTable}

\end{document}

For an improved alignment of the numbers, you could also make use of the siunitx package as shown in the following example:

enter image description here

\documentclass{report}
\usepackage{geometry}
\usepackage[textfont=it]{caption} 
\usepackage{booktabs}
\usepackage{longtable}
\usepackage[flushleft, para, referable]{threeparttablex}
\usepackage{siunitx}
\begin{document}

\begin{ThreePartTable}
\begin{TableNotes}
\note Abbr = Explanation.
\end{TableNotes}
\small
\setlength{\tabcolsep}{3pt}
\begin{longtable}{cccccS[table-format=2]ccccS[table-format=2]cS[table-format=2]S[table-format=2]c}
\caption[This is my table]{In reality it has 74 rows}\\
\toprule
& & & & & & & &  \multicolumn{3}{c}{ADOS} & \multicolumn{4}{c}{ADI-R}\\
\cmidrule(r){9-11} \cmidrule(l){12-15}
ID& Age & Sex & Group & WST & {IQ} & Code &    AQ  &  Kommun. &  Sozial &  {Total} & Sozial &  {Kommun.} &  {Verh.} &  Beginn\\
\midrule
\endfirsthead
\bottomrule
\insertTableNotes\\
\endlastfoot
1&29&w&ASS&21&85&AS& 40  &5&7&12    &   14&10&2&3 \\
2&26&m&ASS&27&93&FA& --- &5&9&14&   23&16&5&3\\
3&31&m&ASS&31&101&FA& 29 &4&5&9&        30&16&11&4\\
4&25&w&ASS&34&110&AS&35&3&8&    11& 21& 13& 6&  2\\
5&35&m&ASS&33&107&AS&43&2&5&    7&  17& 4&  4& \\
\end{longtable}
\end{ThreePartTable}

\end{document}
  • This looks really cool thank you! I wish I could use it but now I get this message:! LaTeX Error: Command \tnote already defined. What can I do about it? – Pia Ge Jul 29 at 20:46
  • @PiaGe: Did you recieve this error message with the MWE from my question or if you add the code into your actual thesis document? – leandriis Jul 29 at 20:48
  • the second thing – Pia Ge Jul 29 at 20:49
  • @PiaGe: Without knowing what other packages you load in your thesis I can unfortunately not help you. Therefore please try to make a minimal working example (MWE) that allows me to reproduce the issue you describe. – leandriis Jul 29 at 20:51
  • 1
    @PiaGe If you use scrreprt the packages caption, geometry and fancyhdr is unnecessary, because scrreprt has internal commands that give similar or better results. In addition, you load caption twice. You should load xcolor instead of color. The problems seems to be that you load a program that define a command called tnote, which threeparttablex also tries to define. – Sveinung Jul 30 at 9:56

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.