1

I'm building a large table (30x37, though I'll only include a few rows in the mwe), and struggling to get the columns to be spaced appropriately.

So far, while the text is small enough to fit on the page if spaced appropriately, either the columns themselves are sized smaller than the text and horizontal space (as shown). For some reason, when the width is set low (try 5in), the hlines do not fill the page, but the columns are spaced more appropriately. This persists whether I resize the 3rd column (as shown) or only use Y columns (defined to be X columns with centered text), and persists if I change all Y to X columns. Whether I define the width as \textwidth, \hsize, \linewidth, or 10.5in doesn't seem to change it, either.

What have I done wrong?

\documentclass[landscape]{article}
\usepackage[letterpaper,margin=.25in]{geometry}

\usepackage{amsmath,amssymb,amsthm,multicol,tabularx}

%center columns = Y
\newcolumntype{Y}{>{\centering\arraybackslash}X} 
%multi-columns that are left-aligned
\newcommand{\mc}[2]{\multicolumn{#1}{l}{#2}} %e.g., \mc{4}{VAP}
%multi-rows that are centered
\newcommand{\mr}[2]{\multicolumn{#1}{*}{#2}} %e.g., \mr{5}{BPI}

\setlength{\parindent}{0em}

\begin{document}

    \begin{tiny}
\begin{tabularx}{\linewidth}{*{2}{|Y}|p{5em}|*{34}{Y|}} %{|*{37}{Y|}}
 &  &  & \mc{4}{Era 1}       & \mc{12}{Era 2}                       & \mc{14}{Era 3}                           & \mc{4}{Era 4}       \\ 
 &  &  & F06 & S07 & F07 & S08 & F08 & S09 & F09 & S10 & F10 & S11 & F11 & S12 & F12 & S13 & F13 & S14 & F14 & S15 & F15 & S16 & F16 & S17 & F17 & S18 & F18 & S19 & F19 & S20 & F20 & S21 & F21 & S22 & F22 & S23 \\ \hline
 Loc    &   A123    &   Long name   &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &   x   &       &       &       &       &       &       &       \\  \hline
\end{tabularx}
    \end{tiny}

\end{document}

The above code produces this

2
  • Welcome to TeX.SE! tabularx has limited number of columns (to 20). You should increase alowed column number or stick with other table package.
    – Zarko
    Dec 27, 2022 at 16:57
  • @Zarko Thank you! I've dug around some but can't figure out how I would increase the allowed column number if I wanted to – could you point me in the right direction?
    – Kveylet
    Dec 31, 2022 at 0:41

3 Answers 3

1

I don't think you want tabularx here as there is no linebreakig

enter image description here

\documentclass[landscape]{article}
\usepackage[letterpaper,margin=.25in]{geometry}

\usepackage{amsmath,amssymb,amsthm,multicol,tabularx}

%center columns = Y
\newcolumntype{Y}{>{\centering\arraybackslash}X} 
%multi-columns that are left-aligned
\newcommand{\mc}[2]{\multicolumn{#1}{l}{#2}} %e.g., \mc{4}{VAP}
%multi-rows that are centered??? you used \multicolumn not row ???
\newcommand{\mr}[2]{\multicolumn{#1}{c}{#2}} %e.g., \mr{5}{BPI}

\setlength{\parindent}{0em}

\begin{document}

X\dotfill X

\setlength\tabcolsep{3pt}
    \begin{tiny}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}*{2}{|c}|l|*{34}{c|}@{}} %{|*{37}{Y|}}
 &  &  & \mc{4}{Era 1}       & \mc{12}{Era 2}                       & \mc{14}{Era 3}                           & \mc{4}{Era 4}       \\ 
 &  &  & F06 & S07 & F07 & S08 & F08 & S09 & F09 & S10 & F10 & S11 & F11 & S12 & F12 & S13 & F13 & S14 & F14 & S15 & F15 & S16 & F16 & S17 & F17 & S18 & F18 & S19 & F19 & S20 & F20 & S21 & F21 & S22 & F22 & S23 \\ \hline
 Loc    &   A123    &   Long name   &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &   x   &       &       &       &       &       &       &       \\  \hline
\end{tabular*}
    \end{tiny}

\end{document}
1
  • Thanks for the catch about the multirow not actually being for rows, too! I bet that Zarko's comment was right, that I didn't know tabularx had a 20 column limit, rather than any linebreak issues, but your solution achieves what I'd hoped for.
    – Kveylet
    Dec 31, 2022 at 0:29
1

An alternative using the tabularray package:

\documentclass[landscape]{article}
\usepackage[letterpaper,margin=.25in]{geometry}


\usepackage{tabularray}

\begin{document}

\noindent\begin{tblr}{
cells={font=\tiny},
colspec={XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX},
columns={c},
column{3}={l},
colsep={1pt},
vlines
}
 &  &  & \SetCell[c=4]{c} Era 1    &&&  & \SetCell[c=12]{c} Era 2 &&&&&&&&&&&                      & \SetCell[c=14]{c} Era 3 &&&&&&&&&&&&&                          & \SetCell[c=4]{c} Era 4 &&&       \\ 
 &  &  & F06 & S07 & F07 & S08 & F08 & S09 & F09 & S10 & F10 & S11 & F11 & S12 & F12 & S13 & F13 & S14 & F14 & S15 & F15 & S16 & F16 & S17 & F17 & S18 & F18 & S19 & F19 & S20 & F20 & S21 & F21 & S22 & F22 & S23 \\ \hline
 Loc    &   A123    &   Long name   &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &       &   x   &       &       &       &       &       &       &       \\  \hline
\end{tblr}

\end{document}
0

Let extend my comment to an answer:

%---------------------------------------------------------------%
%   fix for tabularx when it has more than 23 columns and page  %
%   layout is determined by the package geometry with option    %
%   margin=<width>.                                             %
%   fix provided me David Carlisle in chat 2018.07.25 at 0:43   %
%---------------------------------------------------------------%
\documentclass[landscape]{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage[margin=20mm]{geometry}
\usepackage{tabularx}
% fix -----------------------------------------------------------%
\makeatletter
\def\TX@endtabularx{%
   \expandafter\expandafter\expandafter
     \TX@find@endtabularxa\csname end\TX@\endcsname
     \endtabularx\TX@\endtabularx\TX@find@endtabularxa
  \expandafter\TX@newcol\expandafter{\tabularxcolumn{\TX@col@width}}%
  \let\verb\TX@verb
  \def\@elt##1{\global\value{##1}\the\value{##1}\relax}%
  \edef\TX@ckpt{\cl@@ckpt}%
  \let\@elt\relax
  \TX@old@table\maxdimen
  \TX@[email protected]\TX@target%<<<<< smaller initial guess for big table
  \global\TX@cols\@ne
  \TX@typeout@
    {\@spaces Table Width\@spaces Column Width\@spaces X Columns}%
  \TX@trial{\def\NC@rewrite@X{%
          \global\advance\TX@cols\@ne\NC@find p{\TX@col@width}}}%
  \loop
    \TX@arith
    \ifTX@
    \TX@trial{}%
  \repeat
  {\let\@footnotetext\TX@ftntext\let\@xfootnotenext\TX@xftntext
    \csname tabular*\expandafter\endcsname\expandafter\TX@target
      \the\toks@
    \csname endtabular*\endcsname}%
  \global\TX@ftn\expandafter{\expandafter}\the\TX@ftn
  \ifnum0=`{\fi}%
   \expandafter\expandafter\expandafter
   \TX@find@endtabularxbb
    \expandafter\end\expandafter{\TX@}%
    \endtabularx\TX@\endtabularx\TX@find@endtabularxb
}
% end fix -------------------------------------------------------%
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\newcommand{\mc}[2]{\multicolumn{#1}{l}{#2}}


\begin{document}
\begingroup
\tiny
\setlength\tabcolsep{3pt}
\centering
\begin{tabularx}{\linewidth}{*{2}{|Y}|p{5em}|*{34}{Y|}} %{|*{37}{Y|}}
    &   &   & \mc{4}{Era 1} & \mc{12}{Era 2}                       & \mc{14}{Era 3}                           & \mc{4}{Era 4}       \\
    &     &     & F06 & S07 & F07 & S08 & F08 & S09 & F09 
    & S10 & F10 & S11 & F11 & S12 & F12 & S13 & F13 & S14 
    & F14 & S15 & F15 & S16 & F16 & S17 & F17 & S18 & F18 
    & S19 & F19 & S20 & F20 & S21 & F21 & S22 & F22 & S23 \\ 
    \hline
Loc &A123 & Long name 
                &     &     &     &     &     &     & 10      
    &     &     &     &     &     &     &     &     &   & 20     
    &     &     &     &     &     &     &     &     &       
    &     & x   &     &     &     &     &     &            \\  
    \hline
\end{tabularx} 
\endgroup
\end{document}

enter image description here

1
  • Wow! I appreciate your work on this tremendously. Thank you
    – Kveylet
    Jan 7, 2023 at 15:50

You must log in to answer this question.

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