I'm trying to create a number of running totals using the FP package. I define a macro for adding numbers to a running total and then I define a macro to output the final value.
The problem I'm having is that I receive a different output from the totals macro depending on where I call it. If it's inside the table I receive the correct value however if it's outside then the value doubles.
Any ideas?
\documentclass[11pt]{report}
\usepackage{fp}
\usepackage{tabu,longtable}
\FPset\totalone{0}
\FPset\totaltwo{0}
\def\add#1{%
\FPadd\0\totalone{#1}
\global\let\totalone\0
\FPadd\0\totaltwo{#1}
\global\let\totaltwo\0
#1
}
\def\ptotalone{%
\totalone
\FPset\0{0}\global\let\totalone\0
}
\def\ptotaltwo{%
\totaltwo
\FPset\0{0}\global\let\totaltwo\0
}
\begin{document}
\begin{table}[htbp]
\begin{longtabu}{c}
\add{0.25} \\
\add{0.5} \\
\add{1} \\
total one: \ptotalone
\end{longtabu}
\end{table}
total two: \ptotaltwo
\end{document}
Example output:
0.25
0.5
1
total one: 1.75
total two: 3.5
longtabumakes two passes over the tabular material. – egreg Jan 24 '13 at 11:44