2

Recently I want to create a large table with many columns on a page. To simplify the problem, I have a minimum working example like this:

\documentclass{article}
\usepackage[paperheight=20.1cm, paperwidth=60cm]{geometry}
\usepackage{tabularx}
\begin{document}
\begin{table}[h]
\centering
\begin{tabularx}{\linewidth}{XXXXXXXXXXXXX}
a&a&a&a&a&a&a&a&a&a&a&a&a
\end{tabularx}
\end{table}
\end{document}

When I compile this tex file, I get warning like Overfull \hbox (5.00002pt too wide) in paragraph at lines** many times. And the output is not something I expected: Output PDF File However, when I change the XXXXXXXXXXXXX to p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}, all things go back to normal. It seems that the width of column X is not determined correctly. May you explain why this is happening?

2
  • \begin{tabularx}{.97\linewidth} works, but \begin{tabularx}{.98\linewidth} does not. Very interesting. Also, with \linewidth, paperwidth=58cm works, but not paperwidth=59cm. – Steven B. Segletes Apr 19 at 0:12
  • You can use \usepackage[debugshow]{tabularx}. Then it will tell you (tabularx) Don't exceed \maxdimen (tabularx) Reached minimum width, backing up.. The interpretation of these messages is obvious: it does not work. – user240002 Apr 19 at 2:12
3

As noted in comments under the question tabularx gives a hint if you use debugshow In this case it is doing a specific test to prevent some internal calculations exceeeding \maxdimen and giving errors and spurious results. But in this case it's being over-cautious and backing up when it doesn't have to. If you simply remove the test it does the right thing.

Probably there is room for improvement here but this works on your test file

\documentclass{article}
\usepackage[paperheight=20.1cm, paperwidth=60cm]{geometry}
\usepackage[debugshow]{tabularx}

\makeatletter
\def\TX@arith{%
  \TX@false
  \@tempdimb\maxdimen
  \divide\@tempdimb\TX@cols
%  \ifdim\TX@col@width>\@tempdimb
%    \TX@typeout@{Don't exceed \maxdimen}%
%    \wd\@tempboxa\maxdimen
%  \fi
  \ifdim\TX@old@table=\wd\@tempboxa
    \TX@col@width\TX@old@col
    \TX@typeout@{Reached minimum width, backing up.}%
  \else
    \dimen@\wd\@tempboxa
    \advance\dimen@ -\TX@target
    \ifdim\dimen@<\TX@delta
      \TX@typeout@{Reached target.}%
    \else
      \ifnum\TX@cols>\@ne
        \advance\TX@cols\m@ne
      \fi
      \divide\dimen@\TX@cols
      \advance\dimen@ -\TX@col@width
      \ifdim \dimen@ >\z@
        \PackageWarning{tabularx}%
           {X Columns too narrow (table too wide)\MessageBreak}%
        \TX@col@width\TX@error@width\relax
      \else
        \TX@old@col\TX@col@width
        \TX@old@table\wd\@tempboxa
        \TX@col@width-\dimen@
        \TX@true
      \fi
    \fi
  \fi}
\makeatother
\begin{document}
\begin{table}[h]
\centering
X\dotfill X

\setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{XXXXXXXXXXXXX}
a&a&a&a&a&a&a&a&a&a&a&a&a
\end{tabularx}
\end{table}
\end{document}

enter image description here

5
  • My world is shattered! This is the first time I have seen a DC algorithm function in a sub-optimal manner. – Steven B. Segletes Apr 19 at 10:51
  • Thanks for your answer. Although I cannot fully understand it, it works well :) – zsLiu Apr 19 at 11:58
  • @zsLiu sorry the answer is mainly a note to myself, some code that I wrote 30 years ago isn't doing the right thing, I'll check later what it should be doing. – David Carlisle Apr 19 at 16:51
  • @StevenB.Segletes I blame you. – David Carlisle Apr 19 at 16:51
  • I'm so excited to hear that in 30 years, my coding will become flawless. Can't wait! – Steven B. Segletes Apr 19 at 17:11
1

Obviously you need a linewidth of at least 215pt, probably due to the fact that you want some content in 13 columns. This works without any error:

\documentclass{article}%
\usepackage[paperheight=20.1cm, paperwidth=60cm]{geometry}%
\usepackage{tabularx}%
\begin{document}%
\begin{table}[h]%
\centering%
\begin{tabularx}{215pt}{XXXXXXXXXXXXX}%The maximum without a mistake is exactly {1170pt}. I cannot tell why.
a&a&a&a&a&a&a&a&a&a&a&a&a%
\end{tabularx}%
\end{table}%
\end{document}%

The point @Steven makes would indicate that there are margins within the table and that 13 column are too many, because this works as well, with 12 column, and the output is attached.

\documentclass{article}%
\usepackage[paperheight=20.1cm, paperwidth=60cm{geometry}%
\usepackage{tabularx}%
\begin{document}%
\begin{table}[h]%
\centering%
\begin{tabularx}{\linewidth}{XXXXXXXXXXXX}%
a&a&a&a&a&a&a&a&a&a&a&a%
\end{tabularx}%
\end{table}%
\end{document}%

screenshot 12 columns

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.