# \newenvironment or \newcommand for \xltabular

I'd like to have a shorthand to trigger a table like tabularx, with multipage option like longtable. Neither \newenvironment nor \newcommand I can coax to work

The weird @.. construction at the beginning of the setup of xltabular is for discarding the indentation that is otherwise added. Everything before the actual document takes place in a class file, if that makes a difference. Interpreter needs to be XeLaTex. There does not seem to be a command-version of begin/end xltabular, which is how the problem with environment is solved in tabularx-cases.

M(n)WE:

\documentclass[10pt]{article}
\usepackage{xltabular} % mixture of tabularx and longtable

%%  Either like this (1)
%\newenvironment{threetable}
%{\begin{xltabular}{\linewidth}{@{} X @{\hspace{20pt}} X @{\hspace{20pt}} X @{}}} {\end{xltabular}}

%% Or like this (2)
%\newcommand{\startthreetable}{\begin{xltabular}{\linewidth}{@{} X @{\hspace{20pt}} X @{\hspace{20pt}} X @{}}}
%\newcommand{\stopthreetable}{\end{xltabular}}

\begin{document}

\begin{xltabular}{\linewidth}{@{} X @{\hspace{20pt}} X @{\hspace{20pt}} X @{}}
Content & content & CONTENT
\end{xltabular}

%% (1)
%\begin{threetable}
%Content & content & CONTENT
%\end{threetable}

%% (2)
%\startthreetable
%Content & content & CONTENT
%\stopthreetable

\end{document}

• not sure what you see weird in @{..} that is unrelated to xltabular it is basic latex syntax to specify intercolumn material and applies to tabular in the core format and has been in latex since the start. – David Carlisle Apr 24 '20 at 13:55

As documented in the tabularx manual (xltabular is basically a wrapper around tabularx to incorporate longtable) you need to use the command form inside enviornment definitions

\documentclass[10pt]{article}
\usepackage{xltabular} % mixture of tabularx and longtable

\newenvironment{threetable}
{\xltabular{\linewidth}{@{} X @{\hspace{20pt}} X @{\hspace{20pt}} X @{}}} {\endxltabular}

\begin{document}

\begin{xltabular}{\linewidth}{@{} X @{\hspace{20pt}} X @{\hspace{20pt}} X @{}}
Content & content & CONTENT
\end{xltabular}

\begin{threetable}
Content & content & CONTENT
\end{threetable}

\end{document}


the @{...} construct here is not specific to any of these packages it is basic LaTeX syntax applying to tabular and all its extensions, it specifies inter-column material.

• this is acutally something i tried. probably lost a } somewhere and figured it was a dead end. The resulting error messages seemed to be critical about the @. Wow. Thanks. About the 'weirdness' of the @: in the eye of the beholder, i.e.tardigrada have been with us 'from the start' as well, and qualify for weird as well. – bukwyrm Apr 24 '20 at 14:28
• if you could add a sentence or two in opening of your answer about packages inherit their behavior, i'd like to accept this answer after the obligatory wait. – bukwyrm Apr 24 '20 at 14:30
• @bukwyrm There is no general inheritance mechanism, the whole thing is specific to the way tabularx is implemented so I'm not sure what I could say. (also just at the moment I'd rather have +10 from an upvote than +15 from an accept, to get a nice total score:-) I don't think I have ever looked at the xltabular documentation before but it doesn't say much other than that it works like tabularx. – David Carlisle Apr 24 '20 at 14:42
• @bukwyrm I added something. – David Carlisle Apr 24 '20 at 14:45
• @bukwyrm well no latex syntax is that "natural" but I'm interested why you find @{hello} to put hello between columns more weird than other similar syntax like p{1cm} for a 1cm wide column or >{\bfseries} for a bold column. – David Carlisle Apr 27 '20 at 10:03