I'm trying to define a new environment that encloses a tabularx
environment within some other environment to provide some formatting (such as center
to centre the whole thing). The following was my attempt, but it generates the familiar ! File ended while scanning use of \TX@get@body
error. However, I am already using the \tabularx
command in my definition, which is usually the fix for this error.
The following is my 'MWE' attempt that is broken:
\documentclass{article}
\usepackage{tabularx}
\newenvironment{CT}{%
\begin{center}\tabularx{200pt}{XX}}{%
\endtabularx\end{center}}
\begin{document}
\begin{CT}
One & Two
\end{CT}
\end{document}
If I delete the \begin{center}
and \end{center}
then it runs, while the following is perfectly ok:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{center}
\begin{tabularx}{200pt}{XX}
One & Two
\end{tabularx}
\end{center}
\end{document}
I guess the issue is some subtlety about how \tabularx
behaves within \newenvironment
and how it goes looking for the matching \endtabularx
.
\center
and\endcenter
– egreg Dec 1 '20 at 8:48center
environment.) – Martyn Quick Dec 1 '20 at 8:49