I would like to create a table that shows the evaluations of a formula for some given input list.
My initial idea was to evaluate the formula using the fp package within a \@for
loop. This however does not work within a tabular environment.
My current workaround is to use tabto
for formatting but that's obviously not a sustainable way when I want to add longer numbers, have nice vertical or horizontal lines, or just center the whole thing.
Minimal working example using the workaround:
\documentclass{article}
\usepackage{tabto} % just for the workaround
\usepackage{fp}
\begin{document}
\noindent
$a$ \tabto{1cm} $b$ \tabto{2cm} $a+b$\\ % table header
\makeatletter
\FPset{a}{1}
\@for \b:={1, 1.5, 2, 42}\do{
\FPeval{\result}{round(a+b:2)}
\a \tabto{1cm} \b \tabto{2cm} \result \\ % table row
}
\makeatother
\end{document}
- Note that I'm not looking for a
1..N
loop but one that iterates a given list of floating-point values. - fp is not a hard requirement, suggest an alternative if it gets in the way.
- I would appreciate a solution working with pdflatex instead of e.g. something Lua-based.
The Question: How do I generate something like this as an actual table?
Best Answer
Perhaps by using the
pgfplotstable
package