1

I am using tabularx to create a very large description table, where the content of a lot of the cells is either quite long — spanning over more than one line — or requires an explicit new line. A quick example is the following table:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{tabularx}        % splits cells with text longer than the column width
\usepackage{makecell}        % to allow for a header to span over two lines

\newcolumntype{f}{>{\hsize=.2\hsize}X}    % each of the columns has a defined static width
\newcolumntype{s}{>{\hsize=.3\hsize}X}
\newcolumntype{t}{>{\hsize=.5\hsize}X}
\newcommand{\heading}[1]{\multicolumn{1}{|c|}{#1}}   % centering the headers

\begin{document}
\begin{table}
\caption{Sample table}
\centering
    \begin{tabularx}{\textwidth}{|f|s|t|} 

    \hline
    \heading{\textbf{\makecell{Short\\Column}}} & \heading{\textbf{Medium Column}}  & \heading{\textbf{Long Column}} \\ \hline
    
    Value       & Text      & Text              \\ \hline
    Value       & Text      & This text is too long to fit in one line and is automatically split into three   \\ \hline
    Value       & Text      & - 0: Important \newline
                              - 1: instance \newline
                              - 2: where \newline
                              - 3: the lines \newline
                              - 4: are manually \newline
                              - 5: split \newline
                              - 6: into \newline
                              - 7: items        \\ \hline
    Value       & Text      & Text              \\ \hline
    Value       & Text      & Text              \\ \hline
    ...
    Value       & Text      & Text              \\ \hline
    
    \end{tabularx}
\end{table}

\end{document}

Which then goes over the page height limit until it disappears in the end of the page (notice the page number in the middle of the table as well):

enter image description here

Is there a way to make a table like this span over multiple pages? The solutions that I found (e.g. 2014, 2016 and 2017) for problems similar to mine — using packages such as longtable and ltablex— don't work for some of the specifics of the table I already have. I have tried to adapt them to do so, but could not make it work.

Thank you in advance for the help!

2
  • 1
    You also have xltabular (which loads ltablex), but be aware that long tables can break across pages only at the end of a row.
    – Bernard
    Jul 9, 2020 at 14:32
  • If you have this long lists inside of a table cell, probably entirely switching to a nested list might be a better idea. With thie approach you can have pagebreaks wherever needed.
    – leandriis
    Jul 15, 2020 at 8:21

1 Answer 1

1

As suggested @Bernard in his comment, you should

  • not use float table, it prevent to break table over pages
  • for table use xltabular package

Using any sort of long table you should be aware, that those tables can be split between pages only between their rows.

An example of your table is:

\documentclass[12pt]{article}

\usepackage{xltabular}        % splits cells with text longer than the column width
\newcolumntype{f}{>{\hsize=.2\hsize\hsize=\linewidth}X}    % each of the columns has a defined static width
\newcolumntype{s}{>{\hsize=.3\hsize\hsize=\linewidth}X}
\newcolumntype{t}{>{\hsize=.5\hsize\hsize=\linewidth}X}
\usepackage{makecell}        % to allow for a header to span over two lines
\renewcommand\theadfont{\bfseries}

\begin{document}
\begingroup
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
    \begin{xltabular}{\textwidth}{|f|s|t|} 
\caption{Sample table}
\label{tab:longtable}   \\
    \hline
\thead{Short Column}   & \thead{Medium Column}   & \thead{Long Column}     \\
    \hline
\endfirsthead
\caption[]{Sample table (cont.)}\\
    \hline
\thead{Short Column}   & \thead{Medium Column}   & \thead{Long Column}     \\
    \hline
\endhead
\multicolumn{3}{r}{\footnotesize\itshape{Continued on the next page}}           \\
\endfoot
\endlastfoot
%   table body
Value       & Text      & Text              \\ \hline
Value       & Text      & This text is too long to fit in one line and is automatically split into three   \\ \hline
Value       & Text      & - 0: Important \newline
                          - 1: instance \newline
                          - 2: where \newline
                          - 3: the lines \newline
                          - 4: are manually \newline
                          - 5: split \newline
                          - 6: into \newline
                          - 7: items        \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
Value       & Text      & Text              \\ \hline
    \end{xltabular}
\endgroup

\end{document}

enter image description here

2
  • Why do was there a zero score? Now +1
    – Sebastiano
    Dec 31, 2021 at 7:44
  • 1
    @Sebastiano, I don't know :-(. Thank you very much! :-)
    – Zarko
    Dec 31, 2021 at 7:49

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.