5

What is the best way to use tabularx X column type in longtable? I read here that ltablex is "ancient" and the same post also mentions tabu but its page mentions that the package might not be properly maintained. So I wonder, which is a preferred way? (also i would like to avoid manually working with multi-columns)

4
  • 2
    personally I'd avoid X in most cases (despite having written that code:-) but maybe try the xltabular package Mar 4, 2020 at 22:17
  • also ltablex code is old (from last century sometime) but it is newer than longtable and tabularx, so age isn't necessarily a bad thing. Mar 4, 2020 at 22:23
  • @DavidCarlisle Maybe I should be more specific since there might be a better way. I am looking for a simple way to auto-wrap cells that are too long so that I can avoid using p{xcm} since the table is being used in different documents with different margins and wrong size will make the cells unnecessarily short (or too long).
    – atapaka
    Mar 4, 2020 at 22:23
  • 1
    it depends but usually something like {llp{.4\textwidth} avoids the overhead of tabularx and still adapts to the document page size Mar 4, 2020 at 22:28

1 Answer 1

5

My new LaTeX3 package tabularray is an alternative to the outdated tabu package. You can use X columns in longtblr environment.

\documentclass[12pt]{article}
\usepackage[a6paper,margin=10mm]{geometry}
\pagestyle{empty}

\usepackage{tabularray}
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{colorlinks}

\begin{document}

Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.
\NewTblrTheme{fancy}{
  \SetTblrStyle{firsthead}{font=\bfseries}
  \SetTblrStyle{firstfoot}{fg=blue}
  \SetTblrStyle{caption-tag}{red}
}
\begin{longtblr}[
  theme = fancy,
  caption = {Long Tabular},
  entry = {Short Caption},
  label = {tblr:test},
  note{a} = {It is the first footnote.},
  note{$\dag$} = {It is the second long long long long long long footnote.},
]{
  colspec = {XXX}, hlines,
  rowhead = 2, rowfoot = 1,
  row{odd} = {gray9}, row{even} = {teal9},
  row{1-2} = {purple7}, row{Z} = {blue7},
}
 Head    & Head  & Head    \\
 Head    & Head  & Head    \\
 Alpha   & Beta  & Gamma   \\
 Epsilon & Zeta  & Eta     \\
 Iota    & Kappa & Lambda  \\
 Nu      & Xi    & Omicron \\
 Rho     & Sigma & Tau     \\
 Phi     & Chi   & Psi     \\
 Alpha   & Beta  & Gamma   \\
 Epsilon & Zeta\TblrNote{a}       & Eta    \\
 Iota    & Kappa\TblrNote{$\dag$} & Lambda \\
 Nu      & Xi    & Omicron \\
 Rho     & Sigma & Tau     \\
 Phi     & Chi   & Psi     \\
 Alpha   & Beta  & Gamma   \\
 Epsilon & Zeta  & Eta     \\
 Iota    & Kappa & Lambda  \\
 Nu      & Xi    & Omicron \\
 Rho     & Sigma & Tau     \\
 Phi     & Chi   & Psi     \\
 Foot    & Foot  & Foot    \\
\end{longtblr}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text.

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .