How does one automatically add a \bottomrule
at the end of a tabularx
environment?
\documentclass{scrartcl}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{etoolbox}
\newenvironment{mytabular}[1]{%
\expanded{\noexpand\begin{tabular}{#1}}%
\toprule%
}{%
\bottomrule%
\end{tabular}%
}%
\newenvironment{mytabularx}[1]{%
%\apptocmd\tabularx{\toprule}{}{\errmessage{Failed to patch tabularx}}
% => Package array Error: Illegal pream-token (\toprule): `c' used.
\expanded{\noexpand\tabularx{\textwidth}{#1}}%
\toprule
% => works
}{%
\endtabularx%
}%
\newenvironment{mytabularX}[1]{%
%\pretocmd\TX@endtabularx{\bottomrule}{}{\errmessage{Failed to patch tabularx}}
% => ./main.tex:59: Misplaced \noalign.
% => \bottomrule ->\noalign
% => {\ifnum 0=`}\fi \@aboverulesep =\aboverulesep \global...
% => l.59 \begin{mytabularX}{Xcrl}
%\preto\TX@endtabularx{\bottomrule}%
% => ./main.tex:59: Misplaced \noalign. (same as above)
\expanded{\noexpand\tabularx{\textwidth}{#1}}%
}{%
%\bottomrule
% => ./main.tex:61: Misplaced \noalign.
% => \bottomrule ->\noalign
% => {\ifnum 0=`}\fi \@aboverulesep =\aboverulesep \global...
% => l.61 \end{mytabularX} (same error, different line)
\endtabularx%
}%
\begin{document}
\begin{mytabular}{lcrl}
this & is & my & table \\
\end{mytabular}
\vspace{2cm}
\begin{mytabularx}{lcrX}
this & is & my & table \\
\end{mytabularx}
\vspace{2cm}
\begin{mytabularX}{Xcrl}
this & is & my & table \\
\end{mytabularX}
\end{document}
The most frustrating part about this is that it works for adding at the beginning of the environment.