我想在新环境中使用spreadtab并编写了此代码。问题是 - 我找不到错误:
\documentclass[a4paper; 11pt; titlepage]{article}
\usepackage{tabularx}
\usepackage{array}
\usepackage{spreadtab}
\newcounter{value}
\newenvironment{tab}{
\begin{spreadtab}{{tabular}{|>{\centering\arraybackslash}m{.35\textwidth}|
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}|
>{\centering\arraybackslash}m{.05\textwidth}|
>{\centering\arraybackslash}m{.08\textwidth}|
>{\centering\arraybackslash}m{.19\textwidth}|}}
\hline}{\hline
\multicolumn{8}{c}{\setcounter{value}{:={sum(b1:[5,-1])}}}\\
\end{spreadtab}
}
\begin{document}
\begin{tab}
@Some text here
& 1 & 2 & 3 & 4 & 5
& 6
& @text
& @TEXT\\
\hline
@Some text here
& 1 & 2 & 3 & 4 & 5
& 6
& @text
& @TEXT\\
\end{tab}
\end{document}
它给了我这个错误信息:
New spreadtab: \begin{tabular}{|>{\centering \arraybackslash }m{.35\textwidth }
| >{\centering \arraybackslash }m{.03\textwidth }@{/} >{\centering \arraybacksl
ash }m{.03\textwidth }@{/} >{\centering \arraybackslash }m{.03\textwidth }@{/}
>{\centering \arraybackslash }m{.03\textwidth }@{/} >{\centering \arraybackslas
h }m{.03\textwidth }| >{\centering \arraybackslash }m{.05\textwidth }| >{\cente
ring \arraybackslash }m{.08\textwidth }| >{\centering \arraybackslash }m{.19\te
xtwidth }|}
* reading tab:)
Runaway argument?
! File ended while scanning use of \ST@get@body@env.
<inserted text>
\par
<*> example.tex
只有在新环境中使用 Spreadtab 时才会发生这种情况。我花了大约一周的时间才找到错误。知道问题出在哪里吗?
编辑:当我使用新命令而不是新环境时也会发生这种情况(错误消息相同):
\newcommand{\begintab}{
\begin{spreadtab}{{tabular}{|>{\centering\arraybackslash}m{.35\textwidth}|
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}|
>{\centering\arraybackslash}m{.05\textwidth}|
>{\centering\arraybackslash}m{.08\textwidth}|
>{\centering\arraybackslash}m{.19\textwidth}|}}
\hline
}
\newcommand{\closetab}{\hline
\multicolumn{8}{c}{\setcounter{value}{:={sum(b1:[5,-1])}}}\\
\end{spreadtab}
}
\begin{document}
\begintab
@Some text here
& 1 & 2 & 3 & 4 & 5
& 6
& @text
& @TEXT\\
\hline
@Some text here
& 1 & 2 & 3 & 4 & 5
& 6
& @text
& @TEXT\\
\closetab
\end{document}
答案1
有趣的问题,但解决方案却很糟糕。;-)
显然,spreadtab
必须看到所有东西都已打包好准备处理。
\documentclass[a4paper; 11pt; titlepage]{article}
\usepackage{tabularx}
\usepackage{array}
\usepackage{spreadtab}
\usepackage{environ}
\newcounter{value}
\NewEnviron{tab}{%
\edef\x{%
\unexpanded{\begin{spreadtab}{{tabular}{
|>{\centering\arraybackslash}m{.35\textwidth}|
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}@{/}
>{\centering\arraybackslash}m{.03\textwidth}|
>{\centering\arraybackslash}m{.05\textwidth}|
>{\centering\arraybackslash}m{.08\textwidth}|
>{\centering\arraybackslash}m{.19\textwidth}|
}}
\hline}
\unexpanded\expandafter{\BODY}
\unexpanded{\hline
\multicolumn{8}{c}{\setcounter{value}{:={sum(b1:[5,-1])}}}\\
\end{spreadtab}}}\x
}
\begin{document}
\begin{tab}
@Some text here
& 1 & 2 & 3 & 4 & 5
& 6
& @text
& @TEXT\\
\hline
@Some text here
& 1 & 2 & 3 & 4 & 5
& 6
& @text
& @TEXT\\
\end{tab}
Here is the value: \thevalue
\end{document}