I love the idea behind spreadtab. The author should be congratulated.

However, it seems to require that I specify specific numbers for the rows that I want to add. What if I have a document, where I am adding more rows every now and then? Is it possible to have a syntax that takes the form 1:lastrow, with lastrow being calculated internally by the package and not me?

• Some kind of a minimum working example would be nice. I'm not sure I understand what you mean by the number of rows having to be specified? (Or do you mean columns?) – A.Ellett Oct 11 '14 at 19:44

Please have a look on the following MWE.

\documentclass{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\begin{document}

12       \\
13       \\
14       \\
\hline
sum(a1:[0,-1]) \\

\end{document}


Please see the line with sum(a1:[0,-1]). With a1 is the first cell named (containing 12). With [0,-1] you can address the cell before. If you are standing in cell a4 (that is the cell were we want to calculate the sum) you call cell a3 with [0,-1].

Btw: with [0,-2] you would call cell a2 with the value 12.

See the result of the given MWE (39 is calculated by function sum):

Btw2: Suppose you want to calculate the sum from cell a1 until d1 in cell e1. Then you can use sum(a1:[-1,0]) in cell e1.

Hope this helps ...

You can also use the tag macro and then write the cell macro in the argument of sum:

\begin{spreadtab}{{tabular}{r}}
12            \\
13            \\% you can add rows
14tag(lastrow)\\\hline
sum(a1:cell(lastrow)) \\


Check this example (using packages longtable and spreadtab) that has zeroed out rows at the beginning and at the end. These two rows are made invisible by \phantom and are moved up by [-6.9mm] at the begininng.

\begin{spreadtab}{{longtable}{cccc}}%
@\textbf{ONE} & @\textbf{TWO} & @\textbf{THREE} & @\textbf{FOUR} \\
[-6.9mm]\phantom{:={0}} & \phantom{:={0}} & \phantom{:={0}} & \phantom{:={0 tag(start)}} \\
5 & 6 & 7 & 8 \\
5 & 6 & 7 & 8 \\
5 & 6 & 7 & 8 \\
[-6.9mm]\phantom{:={0}} & \phantom{:={0}} & \phantom{:={0}} & \phantom{:={0 tag(stop)}} \\
@\textbf{vsota} & sum(cell(start):cell(stop))


This example alows you to split the table by defining two commands somewhere in the preamble of your document.

First:

\newcommand{\tablestart}{
@\textbf{dan} & @\textbf{ure} & @\textbf{vsebine} & @\textbf{status} \\
[-6.9mm]\phantom{:={0}} & \phantom{:={0}} & \phantom{:={0}} & \phantom{:={0 tag(start)}} \\

}


Second:

\newcommand{\tablestop}{
[-6.9mm]\phantom{:={0}} & \phantom{:={0}} & \phantom{:={0}} & \phantom{:={0 tag(stop)}} \\
@\textbf{vsota} & sum(cell(start):cell(stop))


Then you also define one more command for users to be able to easily input data into table:

\newcommand{\input}[4]{
#1 & #2 & #3 & #4 \\
}


And then you can use these three commands in your document in this order:

\tablestart
\input{5}{6}{7}{8}
\input{5}{6}{7}{8}
\input{5}{6}{7}{8}
\tablestop


And table will sum it up!

## ERROR:

While this approach works if you don't split the table, it fails if you split it. Does anyone know why?