1

I am having an issue with a longtable I wish to include in my PhD document. It seems to be a common problem (for example) but I am new to Latex and the solutions I have found have not work for me. The issue is quite simple, the longtable does not fit the width of the page and the column. Here is a MWE:

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[margin=2.5cm]{geometry}
\usepackage{booktabs}
\usepackage{array}
\usepackage{booktabs}
\usepackage{longtable}

\begin{document}

\setlength\LTcapwidth{\linewidth} \setlength\LTleft{\fill} \setlength\LTright{\fill} \begin{longtable}{@{\extracolsep{\fill}}lll@{}}\toprule \textbf{Date} & \textbf{Example - Example and Example} & \textbf{Example - Example and Example} \* \midrule \endhead % \bottomrule \endfoot % \endlastfoot % 1460 & Long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text. & \ 1470 & Long text long text long text long text long text long text long text long text long text long text. & \ 1470-1535 & & Long text long text long text long text long text long text long text long text long text long text long text. \ 1532 & Long text long text long text long text long text long text long text long text long text. & \ 1535-36 & & Long text long text long text long text long text long text long text long text long text long text long text long text long text. \ 1537 & Long text long text long text long text long text long text long text long text long text long text long text long text long text. & \ 1538 & Long text long text long text long text long text long text long text long text long text long text long text. & \ 1541 & & Long text long text long text long text long text long text long text long text long text long text long text long text long text. \

[...]

2021 & & Long text long text long text long text long text long text long text long text. \* \bottomrule \end{longtable}

Thank you for your help.

  • The current example code will most likely not result in a table that is wider than the textwidth. Please prepare an example that allows others to reproduce your issue. – leandriis Oct 17 '21 at 12:05
  • 1
    You may be interested in the xltabular package and its X type column. – leandriis Oct 17 '21 at 12:05
  • Thank you for your comment, I just modified the code to show better the issue. I tried with the xltabular package but I didn't manage to solve the problem. – warped.wood Oct 17 '21 at 12:11
  • I tried again with xltabular and it is perfectly working now. Thank you for the suggestion! – warped.wood Oct 17 '21 at 14:01
  • 4
    I’m voting to close this question because OP claims that it solve himself by use of comment. – Zarko Nov 02 '21 at 18:19

1 Answers1

4

Text in cells of the second and third column is longer than text width, therefore, the cells in these columns must allow the text to be broken into multiple lines. Such fetures has p{width} column type, however, simpler is to use X column type defined in xltabular (which combine tabularx and longtable, longtblr defined in the tabularray package etc.

With longtblr MWE with your table can be as follows:

\documentclass{report}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\usepackage{lipsum}

\begin{document} \begingroup \NewTblrTheme{fancy}{ \SetTblrStyle{head}{font=\small} \SetTblrStyle{foot}{font=\footnotesize\itshape} \SetTblrStyle{caption-tag}{font=\bfseries} }

\begin{longtblr}[

theme = fancy, caption = {Long table \texttt{longtblr}}, label = {tab:longtblr}]{ rowhead = 1, colspec = {@{} l X[j] X[j] @{}}, row{1} = {font=\bfseries} } \toprule Date & Example - Example and Example & Example - Example and Example \* \midrule % table body 1460 & \lipsum[1] & \ 1461 & & \lipsum[2] \ 1470 & \lipsum[3]. & \ 1470-1535 & & Long text long text long text long text long text long text long text long text long text long text long text. \ 1532 & Long text long text long text long text long text long text long text long text long text. & \ 1535-36 & & Long text long text long text long text long text long text long text long text long text long text long text long text long text. \ 1537 & Long text long text long text long text long text long text long text long text long text long text long text long text long text. & \ 1538 & Long text long text long text long text long text long text long text long text long text long text long text. & \ 1541 & & Long text long text long text long text long text long text long text long text long text long text long text long text long text. \

[...] & & \

2021 & & Long text long text long text long text long text long text long text long text. \* \bottomrule \end{longtblr} \endgroup \end{document}

enter image description here

Zarko
  • 296,517
  • Thank you for your answer! I finally managed to solve the problem with the X type column by using the xltabular package. – warped.wood Oct 17 '21 at 15:07