2

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?

  • 2
    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
1

Please have a look on the following MWE.

\documentclass{scrartcl}

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

\begin{document}

\begin{spreadtab}{{tabular}{r}}
12       \\
13       \\
14       \\
\hline
sum(a1:[0,-1]) \\
\end{spreadtab}

\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):

result of the given MWE

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 ...

|improve this answer|||||
1

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)) \\
\end{spreadtab}
|improve this answer|||||
0

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))
\end{spreadtab}

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

First:

\newcommand{\tablestart}{
    \begin{spreadtab}{{longtable}{cccc}}%
        @\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))
    \end{spreadtab}

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?

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.