TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My question concerns the combination of the tabular environment and the \DeclareDocumentEnvironment command (from the xparse package).

How do I set up an environment that contains in its code some of the operators of the tabular environment, such as & or \\ ?

Here is my minimal (not) working example of what I thought I could do, but I get an error :

\DeclareDocumentEnvironment{env}{mm}{\toprule #1 & #2 &}{\\ \bottomrule}


Any idea of what I could do to have this environment working Inside the tabular environment?

Thank you in advance,


share|improve this question
AFAIK, it is not possible to span an environment across cell boundaries. – quinmars Mar 6 '14 at 12:32
@quinmars It's not the only problem: \begin{env} expands to \env which is \protected, so expansion ends here as far as \halign is concerned for finding \noalign, so \toprule shows up too late, when a cell has already been started. – egreg Mar 6 '14 at 14:34

The \toprule will complain if something unexpandable was encountered before. You can circumvent the issue by using plain old commands:


%\DeclareDocumentEnvironment{env}{mm}{\toprule #1 & #2 &}{\\ \bottomrule}

\newcommand{\env}[2]{\toprule #1 & #2 &}
\newcommand{\envend}{\\ \bottomrule}

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.