4
\begin{block}{Command} \newcolumntype{R}{>{\raggedleft\arraybackslash}X}
    \begin{tabularx}{\textwidth}{*{2}{@{}l}@{}R}
        1 & 2 & 3
    \end{tabularx}
\end{block}

Since this is a bit cumbersome, I want to use \newenvironment to make things easier.

\documentclass[10pt]{beamer}

\usepackage{tabularx}

\newenvironment{Command}[1]
{\begin{block}{Command}%
    \newcolumntype{R}{>{\raggedleft\arraybackslash}X}%
    \begin{tabularx}{\textwidth}{*{#1}{@{}l}@{}R}%
}{  \end{tabularx}%
\end{block}}

\begin{document}

% THIS IS CORRECT
% \begin{block}{Command} \newcolumntype{R}{>{\raggedleft\arraybackslash}X}
%     \begin{tabularx}{\textwidth}{*{2}{@{}l}@{}R}
%         1 & 2 & 3
%     \end{tabularx}
% \end{block}

% THIS IS INCORRECT
\begin{Command}{2}
        1 & 2 & 3
\end{Command}

\end{document}

This is what I've tried, but it doesn't work, and the error message is

! Missing } inserted.
<inserted text>
}
l.nn        \end{tabularx}

EDITED

According to the thread @TeXnician mentioned, I tried

\newenvironment{Command}[1]
{   \newcolumntype{R}{>{\raggedleft\arraybackslash}X}%
    \tabularx{\textwidth}{#1}%
}{  \endtabularx}

and it does work. However, if \begin{block}\end{block} are added, the warning pops up:

! Undefined control sequence.
\endbeamercolorbox ->\ifdim \beamer@colbox@sep 
                                               =0pt\else \vskip \beamer@colb...
l.nn ^^I\end{block}

1 Answers1

5

You can try with the environ package:

\documentclass[10pt]{beamer}
\usetheme{warsaw}
\usepackage{tabularx}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\usepackage{environ}


\NewEnviron{Command}[1]
{\begin{block}{command} %
    \begin{tabularx}{\textwidth}{*{#1}{@{}l}@{}R}%
    \BODY
    \end{tabularx}
 \end{block}
}

\begin{document}


\begin{frame}

\begin{Command}{2}
     1 & 2 & 3 \\
     abc & abc & abc
\end{Command}

\end{frame}

\end{document}

enter image description here

Update 3/2019:

It also works with the new xparse version and its new b-type argument:

\documentclass[10pt]{beamer}
\usetheme{warsaw}
\usepackage{tabularx}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}

\usepackage{xparse}
\NewDocumentEnvironment{Command}{m b}
{\begin{block}{command} %
    \begin{tabularx}{\textwidth}{*{#1}{@{}l}@{}R}%
    #2
    \end{tabularx}
 \end{block}
}


\begin{document}


\begin{frame}

\begin{Command}{2}
     1 & 2 & 3 \\
     abc & abc & abc
\end{Command}

\end{frame}

\end{document}
Ulrike Fischer
  • 327,261