I'm having trouble computing the width of a longtable and using it later in the table. This site offers several suggestions and I have implemented one of them. However, because of scope, or because of some of the nuances of longtable, the \global\advance\variable trick isn't working properly.
Below is my current output. The NOTES are supposed to extend to the last column.

Here is the code that produces the figure above. I realize that there are several tricks to get more sophisticated with the use of newenvironment and newcolumntype, but for purposes of debugging, I got close to bare metal. A previous question and answer on this side helped clean up the table and the command \rulefiller is a result of this.
\documentclass[11pt]{article}
\usepackage{array,multirow,ctable,longtable}
\usepackage{color,colortbl}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\setlength{\extrarowheight}{0.25ex}
\newlength{\spacebeforetotals}
\setlength{\spacebeforetotals}{0.5ex}
\newlength{\noteswidth}
\newlength{\spacebeforenotes}
\setlength{\spacebeforenotes}{0.0pt}
\definecolor{pantone120}{cmyk}{0.00,0.06,0.60,0.00} % Pantone 120
\definecolor{buzzgold}{cmyk}{0.00,0.34,1.00,0.12} % Buzz Gold
\newcommand{\tableshadingcolor}{pantone120} % set this to change background shading of tables
\newcommand{\tablerulecolor}{black}
\newcolumntype{L}{>{\columncolor{\tableshadingcolor}}l}
\newcolumntype{C}{>{\columncolor{\tableshadingcolor}}c}
\newcolumntype{R}{>{\columncolor{\tableshadingcolor}}r}
\newcommand*{\rulefiller}{%
\arrayrulecolor{\tableshadingcolor}% change to cell colour
\specialrule{\heavyrulewidth}{0pt}{-\heavyrulewidth}% "invisible" rule
\arrayrulecolor{\tablerulecolor}% revert to regular line colour
}
\newsavebox{\mycolwidthbox}% box to save cells in
\begin{document}
\section{Research}
Table \ref{tab:research1} presents a summary of sponsored research by funds source over time.
\setlength{\global\noteswidth}{-\tabcolsep}%
\textsf{%
% latex table generated in R 2.13.1 by xtable 1.6-1 package
% Mon Oct 24 07:31:24 2011
{\footnotesize
\begin{longtable}{L
>{\begin{lrbox}{\mycolwidthbox}\setlength{\global\noteswidth}{-\tabcolsep}}L<{\end{lrbox}\global\advance\noteswidth by \wd\mycolwidthbox\global\advance\noteswidth by \tabcolsep\usebox{\mycolwidthbox}}
>{\begin{lrbox}{\mycolwidthbox}}R<{\end{lrbox}\global\advance\noteswidth by \wd\mycolwidthbox\global\advance\noteswidth by \tabcolsep\usebox{\mycolwidthbox}}
>{\begin{lrbox}{\mycolwidthbox}}R<{\end{lrbox}\global\advance\noteswidth by \wd\mycolwidthbox\global\advance\noteswidth by \tabcolsep\usebox{\mycolwidthbox}}
>{\begin{lrbox}{\mycolwidthbox}}R<{\end{lrbox}\global\advance\noteswidth by \wd\mycolwidthbox\global\advance\noteswidth by \tabcolsep\usebox{\mycolwidthbox}}
>{\begin{lrbox}{\mycolwidthbox}}R<{\end{lrbox}\global\advance\noteswidth by \wd\mycolwidthbox\global\advance\noteswidth by \tabcolsep\usebox{\mycolwidthbox}}
>{\begin{lrbox}{\mycolwidthbox}}R<{\end{lrbox}\global\advance\noteswidth by \wd\mycolwidthbox\global\advance\noteswidth by \tabcolsep\usebox{\mycolwidthbox}}
>{\begin{lrbox}{\mycolwidthbox}}R<{\end{lrbox}\global\advance\noteswidth by \wd\mycolwidthbox\global\advance\noteswidth by \tabcolsep\usebox{\mycolwidthbox}}L}
\nopagebreak & \multicolumn{7}{@{}L}{\scriptsize } & \\%
\nopagebreak & \multicolumn{7}{@{}L}{\small {\tablename\ \thetable{}}} & \\%
\nopagebreak & \multicolumn{7}{@{}L}{\small {\textbf{Research expenditures by funds source over time}}} & \\%
\nopagebreak & \multicolumn{7}{@{}L}{\scriptsize{dollars}} & \\%
\nopagebreak\rulefiller\cmidrule[\heavyrulewidth]{2-8}
\nopagebreak & variable & FY05 & FY06 & FY07 & FY08 & FY09 & FY10 & \\%
\nopagebreak\rulefiller\cmidrule[\lightrulewidth]{2-8}
\endfirsthead
\nopagebreak & \multicolumn{7}{C}%
{\tablename\ \thetable{} -- continued from previous page} & \\%
\nopagebreak\rulefiller\cmidrule[\heavyrulewidth]{2-8}
\nopagebreak & variable & FY05 & FY06 & FY07 & FY08 & FY09 & FY10 & \\%
\nopagebreak\rulefiller\cmidrule[\lightrulewidth]{2-8}
\endhead
\nopagebreak\rulefiller\cmidrule[\heavyrulewidth]{2-8}
\nopagebreak & \multicolumn{7}{R@{}}{{Continued on next page}} & \\%
\endfoot%
\nopagebreak\rulefiller\cmidrule[\heavyrulewidth]{2-8}%
\nopagebreak & \multicolumn{7}{@{}L}{%
\begin{minipage}[t]{\noteswidth}\vspace{\spacebeforenotes}\scriptsize\noindent
NOTES: Research Expenditures represents the numbers of contracts and the amounts of expenditures for each department or research center for the given fiscal year. Research Expenditures include cost sharing and matching funds; administrative, indirect, and other overhead expenses to the extent that they have been charged to a particular grant or other funding source; teaching, if instruction has formed a part of a separately funded research program or is significantly experimental in nature; and engineering-related research.
\end{minipage}
} & \\%
\nopagebreak & \multicolumn{7}{R@{}}{\scriptsize\textit{GIT analysis of ASEE Profiles 2010}} & \\%
\endlastfoot%
\nopagebreak & Federal & 110,772,000 & 103,329,000 & 107,915,000 & 110,262,000 & 139,247,000 & 127,611,000 & \\
\nopagebreak & Foreign & 1,024,000 & 988,000 & 1,383,000 & 1,929,000 & 1,768,000 & 4,730,000 & \\
& Individual & 5,869,000 & 6,415,000 & 7,167,000 & 8,581,000 & 9,545,000 & 7,886,000 & \\
& Industry & 5,786,000 & 30,474,000 & 32,962,000 & 32,208,000 & 39,622,000 & 38,762,000 & \\
& Local & 118,000 & 62,000 & 24,000 & 92,000 & 50,000 & 82,000 & \\
& Nonprofit & 26,875,000 & 6,109,000 & 6,608,000 & 10,310,000 & 12,741,000 & 9,179,000 & \\
\nopagebreak & State & 51,750,000 & 56,300,000 & 63,345,000 & 61,954,000 & 54,310,000 & 51,757,000 & \\
[\spacebeforetotals]%
\nopagebreak & (all) & 202,194,000 & 203,677,000 & 219,404,000 & 225,336,000 & 257,283,000 & 240,007,000 & %
\label{tab:research1}
\end{longtable}
}
}
\end{document}
What am I missing? I believe that scoping is handled properly with the \global variable. My only guess is that the longtable environment isn't processing in a manner that works with the \newsavebox and \advance tricks.

`to mark your inline code as I did in my edit. – doncherry Oct 24 '11 at 12:48