在新环境中引用表体

在新环境中引用表体

我正在尝试基于 创建一个新环境tabularx。我希望它\bottomrule在末尾有一个。我如何在新环境定义中引用表格行?现在底线出现在行上方而不是下方。

\documentclass{article}
\usepackage{array, booktabs, tabularx}

\newcolumntype{L}[1]{>{\hsize=#1\hsize\raggedright\arraybackslash}X}
\newenvironment{funtab}[1]{%
  \tabularx{\textwidth}{@{} L{0.4} L{0.6} L{2.0} @{}}
    \toprule
    Operation&\multicolumn{2}{l}{#1}\\
    \midrule
    %Table body location <------------------------
    \bottomrule
}{%
  \endtabularx
}

\begin{document}

\begin{funtab}{My function name goes here}
  item1 & item2 & item 3 \\
  item1 & item2 & item 3 which is long and should wrap around around around around \\
\end{funtab}

\end{document}

答案1

显然使用了\tabularx....\endtabularx“annoys” \bottomrule,没有留下真正的tabular环境组,因此对\tabularx...内容进行分组。

无论如何,如果它应该出现在表格环境的一部分,\bottomrule就必须将其转移到该部分。\end...

\documentclass{article}
\usepackage{array, booktabs, tabularx}

\newcolumntype{L}[1]{>{\hsize=#1\hsize\raggedright\arraybackslash}X}
\newenvironment{funtab}[1]{%
  \begingroup
  \tabularx{\textwidth}{@{} L{0.4} L{0.6} L{2.0} @{}}
    \toprule
    Operation&\multicolumn{2}{l}{#1}\\
    \midrule
    % Table body location <------------------------
}{%
  \bottomrule
  \endtabularx
  \endgroup
}

\begin{document}

\begin{funtab}{My function name goes here}
  item1 & item2 & item 3 \\
  item1 & item2 & item 3 which is long and should wrap around around around around \\
\end{funtab}

\end{document}

相关内容