0

I am using Overleaf and need to create a multi-page table (longtable), composed by n rows and 3 columns, that has the following characteristics:

  1. table width adapted to page width (column width);
  2. first and second columns' cells content vertically and horizontally centered;
  3. third columns' cells text wrapped.

Here is an example to better explain the format type I want to obtain:

enter image description here

I' ve made several attempts with these packages, but didn' t work quite well for all these characteristics:

  • \begin{longtabu} to \columnwidth {|c|c|X|} not solving point 2 and generating a terrible row spacing;
  • \begin{tabularx}{\columnwidth}{|c|c|X|} with \renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}} in the preamble (to vertically center the cells' content) works just fine but won't return a multi-page table.

What are your suggestions? Thx in advance.

1
  • you can just use a normal longtable, with three p (or m) columns. You can set the column widths so the table is full width. Jan 5, 2021 at 21:07

1 Answer 1

1

You could use xltabular for a table that automaticaly adapts to the textwidth and can span multiple pages. However, please be aware that page breaks can only occur between table rows, not within them.

enter image description here

\documentclass{article}
\usepackage{xltabular}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\usepackage[x11names,table]{xcolor}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}

\usepackage{lipsum}
\begin{document}
\begin{xltabular}{\textwidth}{|>{\ttfamily}l|l|X|}
\caption{a caption text} \label{key}\\
\hline
\rowcolor{DarkSeaGreen1}\thead{text} & \thead{text} & \thead{longer text}\\
\hline
\endhead
text & text & \lipsum[4] \\
\hline
text & text & \lipsum[4] \\
\hline
text & text & \lipsum[4] \\
\hline
text & text & \lipsum[4] \\
\hline
text & text & \lipsum[4] \\
\hline
\end{xltabular}
\end{document}
3
  • Thanks very much! How to add a caption? It gives me an error... Jan 5, 2021 at 21:45
  • @LucaGiovanniVoglino: I ahve updated my answer to also inlcude a caption.
    – leandriis
    Jan 5, 2021 at 21:49
  • So appreciated, thx! Jan 5, 2021 at 21:51

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.