I want to create a long table containing some statistical data, such as the sample, the average, and the variance, etc. I am using the pgf
package and its various extensions to do this.
Here is a silly MWE:
\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usepgflibrary{fpu}
\pgfmathsetseed{\number\pdfrandomseed}
\begin{document}
\xdef\Sum{0}
\xdef\Rand{0}
\xdef\Avg{0}
\xdef\Var{0}
\xdef\Sq{0}
%\begin{table}[h]
%\begin{tabular}{|c|c|c|c|c|c|}
%\hline
%Trial & Rand & Sum & Sum-of-squares & Average & Variance\\
%\hline\hline
%\noindent Trial Rand Sum Sum-of-squares Average Variance\\
\noindent\foreach \i in {1 ,...,15} {
%\pgfkeys{/pgf/fpu,/pgf/fpu/output format=sci}
\pgfmathparse{random(10)}
\xdef\Rand{\pgfmathresult}
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=sci}
\pgfmathparse{\Sum+\Rand}
\xdef\Sum{\pgfmathresult}
\pgfmathparse{\Sq+\Rand*\Rand}
\xdef\Sq{\pgfmathresult}
\pgfmathparse{\Sum/\i}
\xdef\Avg{\pgfmathresult}
\pgfmathparse{\Sq/\i-\Avg*\Avg}
\xdef\Var{\pgfmathresult}
\noindent \i,\ %&%
\pgfmathparse{\Rand}\pgfmathresult,\ %&%
\pgfmathparse{\Sum}\pgfmathresult,\ %&%
\pgfmathparse{\Sq}\pgfmathresult, %&%
\pgfmathparse{\Avg}\pgfmathresult, %&%
\pgfmathparse{\Var}\pgfmathresult \\
%\hline
}
%\end{tabular}
%\end{table}
\end{document}
Here is an output (depending on what random numbers you get):
As you can see, the table is commented out, as I have given up on it. I want to generate a document like this with 1000 pages, and see the computed empirical average and variance.
Very closely related:
- How do I use the ampersand (&) inside a foreach or conditional (or other group/environment) when building tables?
- Copy table row n times
- Generate table using the foreach command from pgffor
- how to get rid of extra \hline drawn before start of longtable?
Note: this question has been heavily edited due to showing signs of the XY problem. I will reask problem X in a separate question later.
\foreach
loop, you might want to take a look at thepgfplotstable
package. (Or someone with more experience can show us both how to do it.)