0

When I use NewDocumentEnvironment of xparse and place a table to be inside this environment, I get an extra row at the end. Same code does not cause extra row in standard newenvironment. Is there a solution to this problem? I have tried using \ignorespaces and made entire thing single line without spaces, still the same result. I have compiled a MWE below:

\documentclass{article}

\usepackage{xparse}

\NewDocumentEnvironment{test}{}{%
    \begin{tabular}{|l|l|l|}\hline%
        A & B & C \\\hline%
}{%
    \end{tabular}%
}

\newenvironment{testtwo}{%
    \begin{tabular}{|l|l|l|}\hline%
        A & B & C \\\hline%
}{%
    \end{tabular}%
}

\begin{document}
    \begin{test}
        This & does not & work\\\hline
    \end{test}

    ~\\~\\

    \begin{testtwo}
        This & does & work\\\hline
    \end{testtwo}   
\end{document}

Result:

result

  • 5
  • http://tex.stackexchange.com/questions/42156/too-long-vertical-lines-in-table 2) http://tex.stackexchange.com/questions/277378/too-long-vertical-lines-in-table-when-declarations-must-remain-on-distinct-lines 3) http://tex.stackexchange.com/questions/285333/build-table-in-new-command-results-in-too-long-vertical-lines
  • – Maarten Dhondt Jan 06 '16 at 08:10
  • Thank I now understand the problem better, I thought about extra space causing new row. But that does not help to solve it though, unless I would change \NewDocumentEnvironment. Is there a way around it? – Cem Kalyoncu Jan 06 '16 at 08:48
  • David's answer here http://tex.stackexchange.com/a/277696/46716 defines a new table environment that you should be able to use. – Maarten Dhondt Jan 06 '16 at 09:00