0

My question is basically in the title. I tried, but cannot get it to work, despite the threeparttable documentation explicitly claiming compatibility with tabularx. Here is what I tried so far:

main.tex

\documentclass{scrartcl}
\usepackage{fontspec}
\usepackage[english]{babel}
\usepackage{testpack}

\usepackage{lipsum}

\begin{document}

\begin{tabxn}{label}{Caption}{Xr}{\textwidth}
  Head A      & Head B \\
  \midrule
  \lipsum[1]  & Something\tnote{a}
\tabxnotes
  \item[a] Some remark;
\end{tabxn}

\end{document}

testpack.sty

\ProvidesPackage{testpack}

\RequirePackage{float}
\RequirePackage{booktabs}
\RequirePackage{tabularx}
\RequirePackage[para,flushleft]{threeparttable}

\makeatletter%
\newcommand{\tabxnotes}{\bottomrule\end{tabularx}\begin{tablenotes}}%
\newenvironment{tabxn}[5][\fps@table]{%
  \expanded{\noexpand\begin{table}[#1]}%
    \label{tab:#2}%
    \caption{#3}%
    \begin{threeparttable}%
      \centering%
      \begin{tabularx}{#5}{#4}%
        \toprule%
}{%
      \end{tablenotes}%
    \end{threeparttable}
  \end{table}%
}%
\newcommand{\tabxnfile}[5][\fps@table]{%
  \begin{scitabxn}[#1]{#2}{#3}{#4}{#5}%
    \input{tab/#2}%
  \end{scitabxn}%
}%
\makeatother%

main.log (excerpt)

Runaway argument?
 \par 
! File ended while scanning use of \TX@get@body.
<inserted text> 
                \par 
<*> main.tex

I know this should tell me that I may have forgotten a closing brace, a \end{env} or something along those lines, but I haven't found anything by triple-checking. How can I get this to work, and if not, what is flawed about the way I approach this?

Edit: Tracing down the bug a bit further, it seems to be in the \tabxnotes command. When I substitute the command for its contents, the MWE compiles. However, to keep things dry, I would like to put that stuff inside one command, instead of three.

4
  • tabularx inside a \newenvironment might be interesting.
    – leandriis
    Commented Apr 5, 2020 at 18:29
  • Now you are adding to my confusion. I constructed another MWE trying to pin down the problem. Using \tabularx *table* \endtabularx creates the same error, while begin{tabularx} *table* \end{tabularx} doesn't. Both in that case outside of the tabxn definition. I did however find out that even with the "working" version, the \tabxnotes command breaks it. What puzzles me the most though, is that three breaking examples give me the same error message.
    – tifrel
    Commented Apr 5, 2020 at 18:48
  • please see the tabularx documentation, you need a different markup to include it in an environment definition. Commented Apr 5, 2020 at 20:57
  • you basically can not do this \newcommand{\tabxnotes}{\bottomrule\end{tabularx}\begin{tablenotes}}% you can define tabularx as par of another environment but you can not start it with one command and end it with another, you have to use an environment form. Commented Apr 5, 2020 at 21:02

1 Answer 1

2

Edit: Tracing down the bug a bit further, it seems to be in the \tabxnotes command.

You basically can not do this

\newcommand{\tabxnotes}{\bottomrule\end{tabularx}\begin{tablenotes}}%

You can define tabularx as part of another environment but you can not start it with one command and end it with another, you have to use an environment form.

Environments are a basic syntactic construct in latex and it is rarely a good idea to hide that syntax. But environments such as tabularx or AMS alignments such as align are special environment forms that require the environment syntax in order to grab the environment body.

2
  • Shouldn't it work then when using the \tabularx ... \endtabularx form?
    – tifrel
    Commented Apr 5, 2020 at 22:39
  • 1
    @tillyboy no. It can not work (not without an unreasonable amount of effort patching things to look like an environment) You need to use the documented syntax, that's the point of the documentation. Commented Apr 5, 2020 at 23:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .