3

I want to use spreadtab in newenvironment and wrote this code. The problem is - I cannot find the mistake:

\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}

It gives me this error message:

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

It happens only when i use spreadtab in new environment. I'm sitting on that about week and I cannot find the error. Any idea where the problem is?

EDIT: It happens also when I use new commands instead new environment (error message the same):

\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}
0

1 Answer 1

2

Interesting problem, with an ugly solution. ;-)

Apparently, spreadtab must see everything already packed up for processing.

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .