我想为我的表创建一个环境。请参阅以下示例:
\documentclass[a4paper,10pt]{scrartcl}
\usepackage{longtable}
\usepackage{booktabs} % \toprule, \bottomrule
\usepackage{tabu}
\begin{document}
\newenvironment{kpTable}
{
\begin{longtabu}{X[1,c] X[1,c]}
\toprule \rowfont{\bfseries}
Foo & Bar\\
\midrule
\everyrow{\tabucline[on 3 pt off 3pt]-}
}
{
\everyrow{}\\
\bottomrule
\caption{} % ERROR: Missing number, treated as zero.
\end{longtabu}
}
\begin{kpTable}
1 & 2 \\
1 & 2 \\
1 & 2
\end{kpTable}
\end{document}
该caption
语句生成错误:“缺少数字,视为零。\[电子邮件保护]“
我该如何修复?
答案1
使用以下包修复它environ
:
\documentclass[a4paper,10pt]{scrartcl}
\usepackage{longtable}
\usepackage{booktabs} % \toprule, \bottomrule
\usepackage{tabu}
\usepackage{environ}
\begin{document}
\NewEnviron{kpTable}
{
\begin{longtabu}{X[1,c] X[1,c]}
\toprule \rowfont{\bfseries}
Foo & Bar\\
\midrule
\everyrow{\tabucline[on 3 pt off 3pt]-}
\BODY
\everyrow{}\\
\bottomrule
\caption{}
\end{longtabu}
}
\begin{kpTable}
1 & 2 \\
1 & 2 \\
1 & 2
\end{kpTable}
\end{document}
正如陈萌的回答中提到的这里