1

I am generating dynamicaly big tables (hundreds of rows and dozens of columns) from python/jinja. I found some solution to make 'subcolumns' widths even: Evenly distributing column widths

So I defined column type:

\newcolumntype{Y}{>{\centering\arraybackslash}X}

the problem is that when number of 'Y' columns reaches 20 the whole table becomes a mess.

full code:

\documentclass{article}
\usepackage[a4paper, landscape, total={11in, 8in}]{geometry}
\usepackage[table]{xcolor}
\usepackage{courier}
\renewcommand*\familydefault{\ttdefault}
\usepackage[T1]{fontenc}
\usepackage{xltabular}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
{
  \begin{xltabular}{\textwidth}{ |*{19}{Y|} }
    \hline
    \rowcolor{lightgray} 
    \multicolumn{3}{ c| }{first} & \multicolumn{3}{ c| }{second} & \multicolumn{2}{ c| }{third} & \multicolumn{2}{ c| }{fourth} &
    \multicolumn{2}{ c| }{fifth} & \multicolumn{2}{ c| }{sixth} & \multicolumn{2}{ c| }{seventh} & \multicolumn{3}{ c| }{eighth}
    \\
    \hline
    \rowcolor{lightgray} 
    a & b & c & d & e & f & g & h & i & j & k & l & m & n & o & p & q & r & s\\
    \hline
    1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
    \hline
    1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
    \hline
    1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
    \hline

\end{xltabular} } \newpage \end{document}

In state above with 19 columns the table looks fine: 19 columns

but if we add just one more Y column:

\begin{xltabular}{\textwidth}{ |*{20}{Y|} }
...

it turns into: 20 or more columns

Adding other types of column like 'c' or 'l' does not affect negatively.

Is there some limit that can be omitted by compiler parameter or something?

Bernard
  • 271,350
Pilchu
  • 11
  • Welcome to tex.sx. – barbara beeton Jul 21 '22 at 13:52
  • it doesn't make sense to use xltabular here. Why don't you use a normal longtable and calculate the width before as something like (\textwidth-n\tabcolsep)/20 ? It will be much faster and less fragile. – Ulrike Fischer Jul 21 '22 at 13:54
  • 1
    It is possible that 40\tabcolsep took up all of the available space leaving nothing for the contents. Try using c columns and standalone to see just how much space you will need. – John Kormylo Jul 21 '22 at 14:04
  • If I remove the option total={11in, 8in}, I am unable to reproduce the issue you're experiencing after adding a 20th column. – Mico Jul 21 '22 at 14:32
  • It would be more useful to provide an example of the problem rather than having to guess how to add a extra colum, where do you span the headings? Also I wrote tabularx but I'd never use it for such a table. tabularx is all about adjusting line breaking within cells to control the total width and you have no line breaking here. – David Carlisle Jul 21 '22 at 16:09

0 Answers0