如何排版34列的tabularx?(错误信息)

如何排版34列的tabularx?(错误信息)

我想要/需要排版一个有 >30 列的非常大的表格,它是我用创建的Excel2LaTeX

我无法编译它,只有当我真的使用 20 列时它才会起作用,但是当我插入第 21 列时,它失败了:

\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}

对不起,我试图使用大纸张格式来使所有内容都可见,但至少当我编译它时,表格奇怪地变得比可见的“页面”还大。

我得到的日志文件包含以下内容:

 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
Package: scrlfile 2011/03/09 v3.09 KOMA-Script package (loading files)

Package scrlfile, 2011/03/09 v3.09 KOMA-Script package (loading files)
                  Copyright (C) Markus Kohm

))) (/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)             used instead.
(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)
                  Copyright (C) Frank Neukam, 1992-1994
                  Copyright (C) Markus Kohm, 1994-

\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)              \headheight     = 17.0pt
(typearea)              \headsep        = 20.40001pt
(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)

我如何修复该表并使其与所有列相编译?

答案1

可能你已经继续了,但是为了记录在案,如果有人想在它进入发行版之前测试它,我认为一个可能的修复方法是tabularx.sty从第 91 行开始更改,这样它看起来像

现有代码:

\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

如果你这样做,请将\ProvidesPackage行改为

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

此修复已纳入tabularxLaTeX 2014 版的分发版本中。

答案2

当 TeX 遇到“尺寸太大”时,几乎无能为力。但没有必要指定 34X列:只需计算长度!

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

按照您的纸张设置,文本宽度为 836.51111pt。836.51111 乘以 20 等于 16730.22220pt,而乘以 21 等于 17566.73331pt。TeX 接受的最大长度略小于 16384pt,这就是问题所在。

显然,表格型需要对每列的文本宽度求和X,以便稍后进行均等划分。也许有更好的方法,但X表格中超过 20 列的情况是例外,而不是常态。

答案3

怎么样?(是的,是的,照这样下去\halign我很快就会成为典型代表)\halign

\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

答案4

只是一个建议

考虑到矩阵的行数和列数太大,无法进行物理打印。如果您将矩阵分成小区域,例如 12 行 x 8 列,并将每个区域打印在一张纸上,您仍然会遇到列宽和行高可能因区域而异的问题,这使得在大型地图上拼接几张纸不切实际。

我已经看到过这种打印件,上面有一张政治地图。类似于您想要获得的东西。这里至关重要的是,每一行的高度都相同。

我看到的替代方案是不同的表示形式。任何矩阵,如果按行和列读取,都可以表示为树。此表示形式相当于编号列表。

您还可以考虑,大矩阵中的每一行都是一个小矩阵。然后列可以变成行,从而简化每个单元格内容的读取。第一列的内容将填充大矩阵的标题,第二列的内容将填充相应单元格的内容。

由于 LaTeX 中的每一行和每个单元格都用命令(\\ 和 &)标记,因此搜索和替换可以帮助进行转换。

相关内容