# tabularx table formats poorly when too long

I have a long, multi-columned tabularx table in a document I'm working with. I'm finding that under certain circumstances the table's formatting breaks.

My minimum working example (works with the commented lines, breaks when they're uncommented):

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

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}


The formatting when not broken (only the first page):

The formatting when broken; i.e., when the document lines are uncommented (only the first page):

The log file from building it:

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@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)


A couple of notes:

• We're fairly set on the formatting of the table's lines, since in its actual usage this is a very long table exported from Excel, and the less editing we have to do to it the better
• This problem isn't correlated with the use of ltablex; without that package, the table will exhibit the same symptoms except it extends from the end of the page
• I can fix this problem by downgrading tabularx to version 2.07. I'm reluctant to use this as a long-term solution, however, since I don't want to use a 17-year-old version of this package.
• Though I only show the first pages of output, in both the broken and working cases the table spans multiple pages
• I do find quite daring that you use X-columns in \multicolumns of different width. Why don't you use longtable + a calculated width instead? – Ulrike Fischer Jul 25 '16 at 21:57
• you have fixed width columns \begin{tabularx}{\textwidth}{p{.5cm}p{.5cm}p{.5cm}p{.5cm}p{.75cm}p{8.75cm}} so tabularx can do nothing useful and has no way to make the table the specified width. Just use longtable here – David Carlisle Jul 25 '16 at 22:15
• Will your labels be systematically periodic? – Bernard Jul 25 '16 at 22:45
• @Bernard, the tables won't be systematically periodic. It's just like that here since I couldn't put in the actual filler – Austin Glaser Jul 25 '16 at 23:01
• My idea was that nested list environments would fit much better (customised with enumitem). There would be no problem with page breaks. – Bernard Jul 25 '16 at 23:28

Within a given table X always gets changed to p{a fixed width} where the width is determined in the beginning. As you have no X columns the algorithm will just give this width some arbitrary spurious small value.

So even if that tabularx had been set up correctly, the entries such as

\multicolumn{3}{X}{...}

\multicolumn{4}{X}{...}


will produce unwanted results, X here does not mean "span 3 or 4 columns and make a parbox that width" it means "span 3 or 4 columns and then centre a parbox of the X width in the middle of that span.

On top of this the ltablex package is a rather eccentric merger of longtable and tabularx and normally I'd just stick to longtable, or here, a list.

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

\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}
`
• +1 A list is really the only solution, especially when it's actually being numbered! – Au101 Jul 30 '16 at 21:30
• @Au101 and it avoids using two of my packages, which must be a good thing:-) – David Carlisle Jul 30 '16 at 21:33