# Nested tabularx doesn't work with ltablex

This works:

\documentclass{article}
\usepackage[a5paper]{geometry}
\usepackage{array}
\usepackage{tabularx}
\setlength{\parindent}{0cm}
\begin{document}
\begin{tabularx}{\textwidth}{ |X|}
\hline
\multicolumn{1}{|@{}c@{}|}{\begin{tabularx}{\dimexpr\hsize-2\arrayrulewidth\relax}
{X}
text \\
\end{tabularx}}\\
\hline
\end{tabularx}
\end{document}


Giving this:

But when I add \usepackage{ltablex} to the preamble, pdflatex starts to give an error:

! Extra alignment tab has been changed to \cr.
<template> \endtemplate

l.16 \end{tabularx}


How to fix? Or, at least, use nested tables in multipage tables?

• Maybe you can achieve the same with ltxtable – Marco Daniel May 20 '13 at 9:40
• @MarcoDaniel ltxtable is not shipped with MikTeX. How to install it? – user4035 May 20 '13 at 9:47
• – Marco Daniel May 20 '13 at 9:49
• @MarcoDaniel Answer says: "Download the content of the package directory", but there is not package directory and no dtx files for ltxtable: ctan.org/pkg/ltxtable, only 1 file. Sorry. – user4035 May 20 '13 at 9:58
• Personally I couldn't recommend tabu, it has some good ideas but it is gratuitously incompatible with standard latex syntax. – David Carlisle May 20 '13 at 23:31

ltablex globally modifies tabularx making it essentially into a longtable. It would probably have been better had it defined a new command but anyway.

Inside the nested \multicolumn a multi-page longtable can't work anyway so you really just want the original tabularx in nested contexts, this defines a \restoretx command that gives you that and allows the example to run without error.

\documentclass{article}
\usepackage[a5paper]{geometry}
\usepackage{array}
\usepackage{tabularx}

\makeatletter
\let\tx@\TX@endtabularx
\def\restoretx{\let\TX@endtabularx\tx@}
\makeatother

\usepackage{ltablex}
\setlength{\parindent}{0cm}
\begin{document}

\begin{tabularx}{\textwidth}{ |X|}
\hline
\multicolumn{1}{|@{}c@{}|}{\restoretx
\begin{tabularx}{\dimexpr\hsize-2\arrayrulewidth\relax}
{X}
text \\
\end{tabularx}}\\
\hline
\end{tabularx}
\end{document}