# How to typeset tabularx with 34 columns? (Error message)

I want/need to typeset a very large table with >30 columns, which I created with Excel2LaTeX.

I don't get it to compile, it only works if I really use 20 columns, however when I insert the 21st one, it fails:

\documentclass[11pt, a3paper, landscape]{scrartcl}
\usepackage{tabularx}
\begin{document}

\begin{tabularx}{\textwidth}{|p{2cm}|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|}
\hline

%with 20 columns it will work:
1 & 2 & 3 & 4 & 5 & 1 & 2 & 3 & 4 & 5 & 1 & 2 & 3 & 4 & 5 & 1 & 2 & 3 & 4 & 5 \\
%with more than 20 columns, it will fail:
%1 & 2 & 3 & 4 & 5 & 1 & 2 & 3 & 4 & 5 & 1 & 2 & 3 & 4 & 5 & 1 & 2 & 3 & 4 & 5 & 1 & 2 & 3 & 4 & 5  \\
\hline
\end{tabularx}
\end{document}


I'm sorry, I tried to use a large paper format to make everything visible, but at least when I compile it, the table gets larger than the visible "page" strangely.

The logfile I get contains the following:

 This is pdfTeX, Version 3.1415926-1.40.11 (TeX Live 2010) (format=pdflatex 2011.7.9)  22 SEP 2011 16:45
entering extended mode
\write18 enabled.
file:line:error style messages enabled.
%&-line parsing enabled.
**TabularXManyColumns.tex
(./TabularXManyColumns.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2009-06-19, ngerman-x-2009-06-19, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnis
h, french, galician, german, ngerman, swissgerman, monogreek, greek, hungarian,
icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, marathi, or
iya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian, kurmanji,
lao, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk, pol
ish, portuguese, romanian, russian, sanskrit, serbian, slovak, slovenian, spani
sh, swedish, turkish, turkmen, ukrainian, uppersorbian, welsh, loaded.
(/usr/local/texlive/2010/texmf-dist/tex/latex/koma-script/scrartcl.cls
Document Class: scrartcl 2011/04/02 v3.09 KOMA-Script document class (article)
(/usr/local/texlive/2010/texmf-dist/tex/latex/koma-script/scrkbase.sty
Package: scrkbase 2011/04/02 v3.09 KOMA-Script package (KOMA-Script-dependent b
asics and keyval usage)

(/usr/local/texlive/2010/texmf-dist/tex/latex/koma-script/scrbase.sty
Package: scrbase 2011/04/02 v3.09 KOMA-Script package (KOMA-Script-independent
basics and keyval usage)

(/usr/local/texlive/2010/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 1999/03/16 v1.13 key=value parser (DPC)
\KV@toks@=\toks14
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/koma-script/scrlfile.sty

))) (/usr/local/texlive/2010/texmf-dist/tex/latex/koma-script/tocbasic.sty
Package: tocbasic 2011/03/23 v3.09 KOMA-Script package (handling toc-files)
)
Package tocbasic Info: omitting babel extension for toc'
(tocbasic)             because of feature nobabel' available
(tocbasic)             for toc' on input line 115.
Package tocbasic Info: omitting babel extension for lof'
(tocbasic)             because of feature nobabel' available
(tocbasic)             for lof' on input line 116.
Package tocbasic Info: omitting babel extension for lot'
(tocbasic)             because of feature nobabel' available
(tocbasic)             for lot' on input line 117.
Package scrartcl Info: You've used obsolete option 11pt'.
(scrartcl)             \KOMAExecuteOptions{fontsize=11pt} will be
(scrartcl)             You may simply replace 11pt'
(scrartcl)             by fontsize=11pt'.
Class scrartcl Info: File scrsize11pt.clo' used to setup font sizes on input l
ine 1246.

(/usr/local/texlive/2010/texmf-dist/tex/latex/koma-script/scrsize11pt.clo
File: scrsize11pt.clo 2011/04/02 v3.09 KOMA-Script font size class option (11pt
)
)
(/usr/local/texlive/2010/texmf-dist/tex/latex/koma-script/typearea.sty
Package: typearea 2011/04/02 v3.09 KOMA-Script package (type area)

Package typearea, 2011/04/02 v3.09 KOMA-Script package (type area)

\ta@bcor=\skip41
\ta@div=\count79
Package typearea Info: You've used standard option landscape'.
(typearea)             This is correct!
(typearea)             Internally I'm using paper=landscape'.
(typearea)             If you'd like to set the option with \KOMAoptions,
(typearea)             you'd have to use paper=landscape' there
(typearea)             instead of landscape', too.
\ta@hblk=\skip42
\ta@vblk=\skip43
\ta@temp=\skip44

Package typearea Warning: Bad type area settings!
(typearea)                The detected line width is about 117%
(typearea)                larger than the heuristically detected line width.
(typearea)                You should e.g. decrease DIV, increase fontsize
(typearea)                or change papersize.

Package typearea Info: These are the values describing the layout:
(typearea)             DIV  = 10
(typearea)             BCOR = 0.0pt
(typearea)             \paperwidth      = 1195.01587pt
(typearea)              \textwidth      = 836.51111pt
(typearea)              DIV departure   = -117%
(typearea)              \evensidemargin = 106.98239pt
(typearea)              \oddsidemargin  = 106.98239pt
(typearea)             \paperheight     = 845.04694pt
(typearea)              \textheight     = 595.80026pt
(typearea)              \topmargin      = -25.16531pt
(typearea)              \topskip        = 11.0pt
(typearea)              \footskip       = 47.60002pt
(typearea)              \baselineskip   = 13.6pt
(typearea)              on input line 1138.
)
\c@part=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\abovecaptionskip=\skip45
\belowcaptionskip=\skip46
\c@pti@nb@sid@b@x=\box26
\c@figure=\count86
\c@table=\count87
\bibindent=\dimen102
) (/usr/local/texlive/2010/texmf-dist/tex/latex/tools/tabularx.sty
Package: tabularx 1999/01/07 v2.07 tabularx' package (DPC)

(/usr/local/texlive/2010/texmf-dist/tex/latex/tools/array.sty
Package: array 2008/09/09 v2.4c Tabular extension package (FMi)
\col@sep=\dimen103
\extrarowheight=\dimen104
\NC@list=\toks15
\extratabsurround=\skip47
\backup@length=\skip48
)
\TX@col@width=\dimen105
\TX@old@table=\dimen106
\TX@old@col=\dimen107
\TX@target=\dimen108
\TX@delta=\dimen109
\TX@cols=\count88
\TX@ftn=\toks16
)
(./TabularXManyColumns.aux)
\openout1 = TabularXManyColumns.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 6.
LaTeX Font Info:    ... okay on input line 6.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 6.
LaTeX Font Info:    ... okay on input line 6.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 6.
LaTeX Font Info:    ... okay on input line 6.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 6.
LaTeX Font Info:    ... okay on input line 6.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 6.
LaTeX Font Info:    ... okay on input line 6.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 6.
LaTeX Font Info:    ... okay on input line 6.

./TabularXManyColumns.tex:13: Dimension too large.
\TX@arith ...\ifdim \TX@old@table =\wd \@tempboxa
\TX@col@width \TX@old@col ...
l.13    \end{tabularx}

? x

Here is how much of TeX's memory you used:
1284 strings out of 493763
19629 string characters out of 3144955
99667 words of memory out of 3000000
4640 multiletter control sequences out of 15000+200000
6379 words of font info for 23 fonts, out of 3000000 for 9000
715 hyphenation exceptions out of 8191
35i,8n,44p,233b,186s stack positions out of 5000i,500n,10000p,200000b,50000s
No pages of output.
PDF statistics:
0 PDF objects out of 1000 (max. 8388607)
0 named destinations out of 1000 (max. 500000)
1 words of extra memory for PDF output out of 10000 (max. 10000000)


How can I fix that table and make it compile with all its columns?

-
tabularx has been updated to address this (2014 release) – David Carlisle May 15 '14 at 10:52

Probably you have moved on, but for the record, and in case anyone wants to test this before it makes its way into a distribution, I think a possible fix would involve changing tabularx.sty from line 91 so it looks like

existing code:

\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


If you do this please change the \ProvidesPackage line to say

\ProvidesPackage{tabularx}
[1999/01/07 v2.07 tabularx' package (DPC) + maxdimen fix]


This fix is incorporated into the tabularx distributed with the 2014 release of LaTeX.

-

When TeX hits "Dimension too large" there's little that can be done. But it's not necessary to specify 34 X columns: just compute the length!

\begin{tabular}{|p{2cm}*{34}{|p{\dimexpr(\textwidth-70\tabcolsep-2cm)/34\relax}}|}


With your paper settings the text width is 836.51111pt. And 836.51111 times 20 makes 16730.22220pt, while times 21 it makes 17566.73331pt. The maximum length accepted by TeX is a tad less than 16384pt and that's where the problem arises.

Apparently, tabularx needs to sum up the textwidth for each X column, in order to later perform the division into equal parts. Maybe there's a better way to proceed, but more than 20 X columns in a table are rather the exception than the rule.

-
thank you very much - that helps me. However I don't understand why tabularx is not able to do the same thing for more than 20 columns. Is that an internal limitation of the package? – MostlyHarmless Sep 22 '11 at 21:33
@Martin I didn't dig deeply enough; however the fact is that dimensions in TeX must be less than 16384pt (~5.76m). I'll add a comment to my answer. – egreg Sep 22 '11 at 21:50
late comment(tex.sx just suggested this page) Wow! learn something every day. With a small test case I get \showthe \wd \@tempboxa showing 22710.0pt. which is more than \maxdimen. Aparently TeX sets the box but the simple equality test \ifdim\TX@old@table=\wd\@tempboxa then generates an error. I didn't know you could have boxes with dimensions bigger than the maximum legal dimen. I'll see if I can make TX avoid this more gracefully. – David Carlisle Feb 2 '12 at 19:54
@egreg, TX doesn't actually sum up the widths, it just sets a trial table into a box, and this box ends up being wider than maxdimen, which I didn't know was possible. – David Carlisle Feb 2 '12 at 19:58
@DavidCarlisle With \setbox0=\hbox{\hskip10000pt\hskip10000pt} TeX doesn't choke. However, it says that \wd0 is -15536.0pt. :) – egreg Feb 2 '12 at 20:51

How about \halign? (Yes, yes, I'm swiftly becoming the poster child for \halign at this rate)

\special{papersize=100cm,297mm}
{\openup1\jot
\everycr={\noalign{\vskip\dp\strutbox}}
%^ compensate for \vtop; it'd be \ht if \vbox was used
\halign{\vtop{\hsize2cm\noindent\raggedright\normalbaselines#}\tabskip1em
&&#\hfil\cr
Lorem ipsum dolor sit amet.& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5 \cr
Lorem ipsum dolor sit amet.& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5& 1& 2& 3& 4& 5 \cr
}
}
\bye

-

I believe that if you use the tabular instead of the tabularx environment and follow egreg's suggestion to compute the width of all but the first column directly, you should not run into a "Dimension too large" issue. The following MWE compiles without a hitch on my system (texlive2011):

\documentclass[11pt, a3paper, landscape]{scrartcl}
\usepackage[margin=2.5cm]{geometry}
\usepackage{lipsum}
\begin{document}
\lipsum[1-3]

\begin{table}[h]
\caption{A table with a header column and 33 normal'' columns}
\begin{tabular}{|p{2cm}*{33}{|p{\dimexpr(\textwidth-68\tabcolsep-2cm)/33\relax}}|}
\hline
&1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 &
11 &12 &13 &14 &15 &16 &17 &18 &19 & 20 &
21 &22 &23 &24 &25 &26 &27 &28 &29 & 30 &
31 &32 &33\\
\hline
\end{tabular}
\end{table}

\lipsum[4-6]
\end{document}


I can't help but provide the following, additional comments: Is it absolutely crucial to display all 34 columns in one (supersized) table? You might do your readers a real favor if you broke up this table into two tables of 17 and 18 columns, respectively (you'd have to repeat the first column, for a new total of 35 columns) or, better still, three separate tables with 12 columns each. Believe me, 12 columns is still plenty to have to take in. Even on A3 paper in landscape mode, the width of each of the 33 data columns is going to be no more than about 1cm, probably forcing you to use either the \scriptsize or \tiny font size to be able to cram in anything into the cells. This will likely further discourage your readers from even trying to take a closer look...

-
thanks for your comments. For the moment, it IS absolutely crucial to display everything to give me an idea, how much space it would consume and to maybe find good ways to split it. It is not a table filled with numbers, but a matrix where by far not all cells will be filled. It shows the relations between process parameters (rows) and product properties (columns), where each cell contains the citations of the sources which observed and effect of parameter X on output Y. As soon as I'll have the overview, I can see how to optimize (=reduce/split/simplify) it. – MostlyHarmless Sep 22 '11 at 20:36
Thanks for replying to my comments about the advisability of creating a table with 34 columns. Good to know that you won't have much "real" text in the cells, but "just" links to citations. Very interesting concept! – Mico Sep 22 '11 at 21:13
I firstly had everything described in the text, but it got far too long so I tried to create a matrix describing the relations between input and output displaying the literature review more clearly. The problem is: too many factors, output variables and sources... so I fear there is no "beautiful" solution for it. And as the numeric citations go up to "330", the space required is quite high if there are >1 citations per cell. So I'll definitely need footnotesize. I'm having 5 such tables (the other 4 are not as large as this one and should fit on ISO A4 landscape with a little effort.) – MostlyHarmless Sep 22 '11 at 21:27
Well, to gain some precious horizontal space, you could load the geometry package with the optional argument [margin=1cm] instead of [margin=2.5cm]. Four more centimeters, or 1.2 mm per column. :-) Best wishes! – Mico Sep 22 '11 at 21:51

Just a sugestion.

Consider that the number of rows and columns of your matrix is too big to be phisically manageable for printing. If you cut your matrix in small regions, say for instance, 12 rows x 8 columns, and print each region in a sheet of paper, you will still have the problem that the column width and row height will probably be different for each region, making unpractical to stitch several sheets of paper on a big map.

I have already seen such type of print out, with a political map. Something similar to what you want to obtain. Here was crucial, that every row was of the same height.

The alternative I see is a different representation. Any matrix, can be expresed as a tree, if you read it by row and by column. This representation is equivalent to a numbered list.

You can consider also, that every row in your big matrix, is a small matrix. Then the columns can become rows, easing the reading of the content of each cell. The content of the first column will be filled with the headings of your big matrix and the content of the second column, will be filled with the content of the respective cell.

Since each row and each cell in LaTeX is marked by commands (\\ and &), a search and replace can help in the transformation.

-