5

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:

enter image description here

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?

Moriambar
  • 11,466
user4035
  • 5,035
  • 6
  • 40
  • 57

1 Answers1

3

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}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
David Carlisle
  • 757,742