我正在处理的文档中有一张很长、多列的 tabularx 表格。我发现在某些情况下表格的格式会中断。
我的最小工作示例(使用注释行,取消注释时会中断):
\documentclass[paper=letter, fontsize=10pt]{article}
\usepackage[english]{babel}
\usepackage{tabularx}
\usepackage{ltablex}
\listfiles
\begin{document}
\begin{tabularx}{\textwidth}{p{.5cm}p{.5cm}p{.5cm}p{.5cm}p{.75cm}p{8.75cm}}
\multicolumn{6}{p{11cm}}{\textbf{A Heading}} \\
1 & \multicolumn{5}{X}{Foo} \\
& 1.1 & \multicolumn{4}{X}{Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap} \\
2 & \multicolumn{5}{X}{Bar} \\
& 2.1 & \multicolumn{4}{X}{More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end} \\
& & 2.1.1 & \multicolumn{3}{X}{Random words words and more words in a fairly long line} \\
& & 2.1.2 & \multicolumn{3}{X}{Other random words in a line} \\
1 & \multicolumn{5}{X}{Foo} \\
& 1.1 & \multicolumn{4}{X}{Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap} \\
2 & \multicolumn{5}{X}{Bar} \\
& 2.1 & \multicolumn{4}{X}{More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end} \\
& & 2.1.1 & \multicolumn{3}{X}{Random words words and more words in a fairly long line} \\
& & 2.1.2 & \multicolumn{3}{X}{Other random words in a line} \\
1 & \multicolumn{5}{X}{Foo} \\
& 1.1 & \multicolumn{4}{X}{Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap} \\
2 & \multicolumn{5}{X}{Bar} \\
& 2.1 & \multicolumn{4}{X}{More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end} \\
& & 2.1.1 & \multicolumn{3}{X}{Random words words and more words in a fairly long line} \\
& & 2.1.2 & \multicolumn{3}{X}{Other random words in a line} \\
1 & \multicolumn{5}{X}{Foo} \\
& 1.1 & \multicolumn{4}{X}{Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap} \\
2 & \multicolumn{5}{X}{Bar} \\
& 2.1 & \multicolumn{4}{X}{More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end} \\
& & 2.1.1 & \multicolumn{3}{X}{Random words words and more words in a fairly long line} \\
& & 2.1.2 & \multicolumn{3}{X}{Other random words in a line} \\
1 & \multicolumn{5}{X}{Foo} \\
& 1.1 & \multicolumn{4}{X}{Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap} \\
2 & \multicolumn{5}{X}{Bar} \\
& 2.1 & \multicolumn{4}{X}{More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end} \\
& & 2.1.1 & \multicolumn{3}{X}{Random words words and more words in a fairly long line} \\
& & 2.1.2 & \multicolumn{3}{X}{Other random words in a line} \\
1 & \multicolumn{5}{X}{Foo} \\
& 1.1 & \multicolumn{4}{X}{Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap} \\
2 & \multicolumn{5}{X}{Bar} \\
& 2.1 & \multicolumn{4}{X}{More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end} \\
& & 2.1.1 & \multicolumn{3}{X}{Random words words and more words in a fairly long line} \\
& & 2.1.2 & \multicolumn{3}{X}{Other random words in a line} \\
1 & \multicolumn{5}{X}{Foo} \\
& 1.1 & \multicolumn{4}{X}{Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap} \\
2 & \multicolumn{5}{X}{Bar} \\
& 2.1 & \multicolumn{4}{X}{More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end} \\
& & 2.1.1 & \multicolumn{3}{X}{Random words words and more words in a fairly long line} \\
& & 2.1.2 & \multicolumn{3}{X}{Other random words in a line} \\
%1 & \multicolumn{5}{X}{Foo} \\
%& 1.1 & \multicolumn{4}{X}{Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap} \\
%2 & \multicolumn{5}{X}{Bar} \\
%& 2.1 & \multicolumn{4}{X}{More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end} \\
%& & 2.1.1 & \multicolumn{3}{X}{Random words words and more words in a fairly long line} \\
%& & 2.1.2 & \multicolumn{3}{X}{Other random words in a line} \\
\end{tabularx}
\end{document}
未损坏时的格式(仅限第一页):
格式损坏时;即当文档行未注释时(仅第一页):
构建时的日志文件:
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=pdflatex 2016.7.5) 25 JUL 2016 14:55
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**document.tex
(./document.tex
LaTeX2e <2016/02/01>
Babel <3.9q> and hyphenation patterns for 81 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty
Package: babel 2016/02/24 3.9q The Babel package
(/usr/share/texlive/texmf-dist/tex/generic/babel-english/english.ldf
Language: english 2012/08/20 v3.3p English support from the babel system
(/usr/share/texlive/texmf-dist/tex/generic/babel/babel.def
File: babel.def 2016/02/24 3.9q Babel common definitions
\babel@savecnt=\count87
\U@D=\dimen103
)
\l@canadian = a dialect from \language\l@american
\l@australian = a dialect from \language\l@british
\l@newzealand = a dialect from \language\l@british
))
(/usr/share/texlive/texmf-dist/tex/latex/tools/tabularx.sty
Package: tabularx 2014/10/28 v2.10 `tabularx' package (DPC)
(/usr/share/texlive/texmf-dist/tex/latex/tools/array.sty
Package: array 2014/10/28 v2.4c Tabular extension package (FMi)
\col@sep=\dimen104
\extrarowheight=\dimen105
\NC@list=\toks14
\extratabsurround=\skip43
\backup@length=\skip44
)
\TX@col@width=\dimen106
\TX@old@table=\dimen107
\TX@old@col=\dimen108
\TX@target=\dimen109
\TX@delta=\dimen110
\TX@cols=\count88
\TX@ftn=\toks15
)
(/usr/share/texlive/texmf-dist/tex/latex/ltablex/ltablex.sty
Package: ltablex 2014/08/13 v1.1 Modified tabularx
(/usr/share/texlive/texmf-dist/tex/latex/tools/longtable.sty
Package: longtable 2014/10/28 v4.11 Multi-page Table package (DPC)
\LTleft=\skip45
\LTright=\skip46
\LTpre=\skip47
\LTpost=\skip48
\LTchunksize=\count89
\LTcapwidth=\dimen111
\LT@head=\box26
\LT@firsthead=\box27
\LT@foot=\box28
\LT@lastfoot=\box29
\LT@cols=\count90
\LT@rows=\count91
\c@LT@tables=\count92
\c@LT@chunks=\count93
\LT@p@ftn=\toks16
))
LaTeX Warning: Unused global option(s):
[paper=letter,fontsize=10pt].
(./document.aux)
\openout1 = `document.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 9.
LaTeX Font Info: ... okay on input line 9.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 9.
LaTeX Font Info: ... okay on input line 9.
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.1|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.2|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.1|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.2|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.1|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.2|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.1|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.2|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.1|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.2|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.1|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.2|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.1|
[]
Overfull \hbox (6.32925pt too wide) in paragraph at lines 63--63
[]|\OT1/cmr/m/n/10 2.1.2|
[]
[1
{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] [2] (./document.aux)
*File List*
article.cls 2014/09/29 v1.4h Standard LaTeX document class
size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
babel.sty 2016/02/24 3.9q The Babel package
english.ldf 2012/08/20 v3.3p English support from the babel system
tabularx.sty 2014/10/28 v2.10 `tabularx' package (DPC)
array.sty 2014/10/28 v2.4c Tabular extension package (FMi)
ltablex.sty 2014/08/13 v1.1 Modified tabularx
longtable.sty 2014/10/28 v4.11 Multi-page Table package (DPC)
***********
)
Here is how much of TeX's memory you used:
823 strings out of 493029
10008 string characters out of 6136235
118871 words of memory out of 5000000
4418 multiletter control sequences out of 15000+600000
3948 words of font info for 15 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
23i,8n,23p,181b,263s stack positions out of 5000i,500n,10000p,200000b,80000s
</usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb></us
r/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on document.pdf (2 pages, 28961 bytes).
PDF statistics:
19 PDF objects out of 1000 (max. 8388607)
12 compressed objects within 1 object stream
0 named destinations out of 1000 (max. 500000)
1 words of extra memory for PDF output out of 10000 (max. 10000000)
几点说明:
- 我们对表格行的格式相当满意,因为在实际使用中,这是一个从 Excel 导出的很长的表格,我们需要对它进行的编辑越少越好
- 该问题与使用无关
ltablex
;如果没有该包,表格将表现出相同的症状,只是它会从页面末尾延伸 - 我可以通过降级
tabularx
到 2.07 版来解决这个问题。但是我不太愿意将其作为长期解决方案,因为我不想使用这个软件包 17 年前的版本。 - 虽然我只展示了输出的前几页,但无论是损坏的还是正常工作的,表格都跨越了多页
答案1
在给定的表中X
总是被改变为p{
固定宽度}
宽度在开始时就已确定。由于没有X
列,因此算法将只为该宽度赋予某个任意的虚假小值。
因此,即使tabularx
设置正确,以下条目
\multicolumn{3}{X}{...}
\multicolumn{4}{X}{...}
将产生不必要的结果,X
这里并不意味着“跨越 3 或 4 列并制作一个该宽度的 parbox”,而是意味着“跨越 3 或 4 列,然后将 X 宽度的 parbox 置于该跨度的中间。
除此之外,该ltablex
软件包是 longtable 和 的一个相当古怪的合并,tabularx
通常我只会坚持longtable
,或者这里的一个列表。
\documentclass{article}
\usepackage[english]{babel}
\usepackage{longtable}
\renewcommand\theenumii{\theenumi.\arabic{enumii}}
\renewcommand\theenumiii{\theenumii.\arabic{enumiii}}
\renewcommand\labelenumii{\theenumii}
\setlength\leftmarginii {2.2em}
\setlength\leftmarginiii {3em}
\listfiles
\begin{document}
\section*{A Heading}
\begin{enumerate}
\item Foo
\begin{enumerate}
\item Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap
\end{enumerate}
\item Bar
\begin{enumerate}
\item More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end
\begin{enumerate}
\item Random words words and more words in a fairly long line
\item Other random words in a line
\end{enumerate}
\end{enumerate}
\item Foo
\begin{enumerate}
\item Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap
\end{enumerate}
\item Bar
\begin{enumerate}
\item More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end
\begin{enumerate}
\item Random words words and more words in a fairly long line
\item Other random words in a line
\end{enumerate}
\end{enumerate}
\item Foo
\begin{enumerate}
\item Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap
\end{enumerate}
\item Bar
\begin{enumerate}
\item More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end
\end{enumerate}
\item Foo
\begin{enumerate}
\item Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap
\end{enumerate}
\item Bar
\begin{enumerate}
\item More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end
\begin{enumerate}
\item Random words words and more words in a fairly long line
\item Other random words in a line
\end{enumerate}
\end{enumerate}
\item Foo
\begin{enumerate}
\item Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap
\end{enumerate}
\item Bar
\begin{enumerate}
\item More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end
\begin{enumerate}
\item Random words words and more words in a fairly long line
\item Other random words in a line
\end{enumerate}
\end{enumerate}
\item Foo
\begin{enumerate}
\item Lorem ipsum dolor sit amet consequetum in farfarbar foobraz do congraftsh thing stuff wrap need enough to make you wrap
\end{enumerate}
\item Bar
\begin{enumerate}
\item More lorem ipsum, or stuff with numbers, that doesn't quite wrap as far end
\end{enumerate}
\end{enumerate}
\end{document}