[Tex/LaTex] newenvironment tabularx and begin center

environmentstablestabularx

I try to create a custom env, based on a tabular. I try to make a \begin{center} before my tabular to remove identation at the beginning of the tabular, but he tells me

"File ended while scanning use of \TX@get@body"

If i remove begin center, it works…

I knew there is some trick to do, as doc said it at §5, they talk about tokens, token register, expandable token, first token and \relax, but it definitively not relaxed me. More seriously, I'm a real noob with latex, and if someone can tell me what I should do for running my tab in a centered environment in my custom env, he will be soo cool!

This is my MWE:

\documentclass{article}
\usepackage{fontspec}

\usepackage{tabularx}

\newenvironment{ffig}{ \begin{center} \tabularx{\linewidth}{|X|X|} }{   \endtabularx \end{center} }


\begin{document}

\begin{ffig}
\hline

voila un beau texte qui sert à rien & ah ben en voila encore un beau tiens  jvais mettre une belle virgule attention la voila, et hop un ptit point.
    \tabularnewline\hline 
          La liberté consiste à pouvoir faire tout ce qui ne nuit pas à autrui : 
      ainsi, l'exercice des droits naturels de chaque homme n'a de bornes que 
      celles qui assurent aux autres Membres de la Société la jouissance de ces 
      mêmes droits. Ces bornes ne peuvent être déterminées que par la Loi. 
          \tabularnewline\hline 
\end{ffig}


\end{document}

Best Answer

Use also the macro form of the center environment, i.e. \center and \endcenter.

(I also added a missing & in the second line so that the last vertical line is drawn again.)

Code

\documentclass{article}
\usepackage{fontspec}
\usepackage{tabularx}

\newenvironment{ffig}{%
    \center
    \tabularx{\linewidth}{|X|X|}%
}{%
    \endtabularx
    \endcenter
}

\begin{document}
\begin{ffig}
    \hline
    voila un beau texte qui sert à rien &
    ah ben en voila encore un beau tiens jvais mettre une belle virgule attention
      la voila, et hop un ptit point. \\ \hline
    La liberté consiste à pouvoir faire tout ce qui ne nuit pas à autrui :
      ainsi, l'exercice des droits naturels de chaque homme n'a de bornes
      que celles qui assurent aux autres Membres de la Société la jouissance
      de ces mêmes droits. Ces bornes ne peuvent être déterminées que par la Loi. &
    \\ \hline
\end{ffig}
\end{document}

Output

enter image description here