# Nested tabularx and itemize => TeX capacity exceeded [input stack size=5000]

I have the problem that I get an error when compiling the MWE (which makes not much sense by itself). I follow the solution from David.

\documentclass[a4paper,11pt]{article}
\usepackage[shorthands=off,bidi=basic,english, ngerman]{babel}
\usepackage{enumerate}
\usepackage{ltablex}
\keepXColumns

\usepackage[font=small, format=hang]{caption}

\begin{document}

\begin{tabularx}{\textwidth}{ X  X }

\multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax} X }{

\begin{tabularx}{\textwidth}{ X  X }

A &  B \\

\end{tabularx}
} \\

\begin{itemize}
\item One item

\end{itemize}
&  ABD \\
\end{tabularx}

\end{document}


When compile the above construct I get TeX capacity exceeded, sorry [input stack size=5000]. \end{tabularx}

Any ideas how to solve this issue?

• ...try not to nest them? Can you provide an image of what you're after? It's not clear why you merge 2 columns only to separate them again via another tabularx... Nov 18 '20 at 18:23
• This seems to be realted to the use of ltablex. If one replaces this package with tabularx, the error message dissapears. However, I also wonder why you place a two column containing tabularx inside of a multicolumn spanning two X type columns. Please add some background information on the intended use. Nov 18 '20 at 18:31
• If you want tabularx-like X type columns in combination with longtable-like mid-table page breaks, you can alternatively use xltabular (instead of the outermost tabularx). Nov 18 '20 at 18:39
• Well the main reason for this construct that it is auto generated. So some user thought about a great idea to have nested tables together with itemize :-| I'm not really happy about the construct, nevertheless it should compile. The whole sample should basically make two tables as something which is listed and than ... I can hardly control if the table is only a short variant or a long table.
– LeO
Nov 18 '20 at 18:49
• Using xltabular instead of ltablex results in a compilable document: \documentclass[a4paper,11pt]{article} \usepackage{enumerate} \usepackage{xltabular} \usepackage[font=small, format=hang]{caption} \begin{document} \begin{xltabular}{\textwidth}{ X X } \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax} X }{ \begin{tabularx}{\textwidth}{ X X } A & B \\ \end{tabularx} } \\ \begin{itemize} \item One item \end{itemize} & ABD \\ \end{xltabular} \end{document} Nov 18 '20 at 18:51

• The column specification

>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax} X


is fundamentally flawed. (The +\arrayrulewidth part is wrong from a purely computational point of view (since your tables don't feature vertical bars), but it doesn't cause the error exception.) Replace the column specification with

p{\dimexpr\textwidth-2\tabcolsep\relax}

• Why the claim of fundamental misspecification? The tabularx package allows users to specify unequal columns widths for columns of type X. However, several sanity checks have to be satisfied. First and foremost, the sum of the relative column widths has to sum to the number of columns of type X. E.g., for a tabularx enviroment with 2 columns of type X, >{\hsize=1.333\hsize}X >{\hsize=0.667\hsize}X is fine since 1.333+0.667=2. Observe that your code does not achieve 2\hsize; instead, it achieves 2\hsize+2\tabcolsep+\arrayrulewidth. This discrepancy alone should tip you off to the fact that something is wrong. The fundamental mistake you're making, then, is that you're trying to use a single column of type X in the second argument of \multicolumn. Hence my suggestion to use a single column of type p.

• Next, the overall width of the "inner" tabularx environment is wrong. Replace

\begin{tabularx}{\textwidth}{ X  X }


with

\begin{tabularx}{\hsize}{XX}


Why? By construction, \textwidth exceeds \hsize by 2\tabcolsep.

• Last but not least, don't forget to insert \noindent immediately before the first, or "outer", tabularx environment -- unless you want to be be bombarded with warning messages that the tabularx environment is too wide.

The following code compiles. That said, I'm certain that it'll ever win a prize for code beauty. For the life of me, I cannot fathom the purpose of the nested tabularx environments. I would never code anything like that in my own LaTeX working papers.

\documentclass{article}
\usepackage{tabularx}

\begin{document}
\noindent % <-- very important
\begin{tabularx}{\textwidth}{XX}

\multicolumn{2}{ p{\dimexpr\textwidth-2\tabcolsep\relax} }{
\begin{tabularx}{\hsize}{XX}
A & B
\end{tabularx}
} \\

\begin{itemize}
\item One item
\end{itemize}
&  ABD
\end{tabularx}

\end{document}

• I'm really impressed about the details. Thx a lot. I need to adjust the width properly and I really grateful for pointing out.
– LeO
Nov 19 '20 at 7:43
• I can follow most of your arguments adapted my code except point 2. If I read the spec of tabularx than it says that X is converted as soon as width is calculated. So I don't see the diff between using X or p. The problem I have with replacing \hsize with \textwidth is when the column below/above has a pic which exceeds the page width. With \hsize it seems to be granted that A4 width is not exceeded.
– LeO
Nov 19 '20 at 10:48
• @LeO - Indeed, the X column type is very much based on the p column type. I wouldn't call the process a "conversion", though, as the X column is a p column. The point of my discussion in the second bullet point was that one has to be quite careful about how one goes about calculating the width of the column or columns. In particular, going from two or more columns to a single column is not exactly trivial. Aside: The remainder of your comment would appear to be based on additional information about which I have no knowledge and about which I therefore cannot comment meaningfully.
– Mico
Nov 19 '20 at 11:54