[pstricks] Generate Table via \readdata
Buddy Ledger
buddyledger at gmail.com
Mon Apr 20 05:44:07 CEST 2009
I've been trying to develop a macro which will typeset a data file into
a table. The code below represents my most sucsessful atempt. I want
to be able to generate a table for any data file which could be used
with listplot. So far I am having trouble generating the column format
string for the tabular environment and I cannot dynamically set the
number of colums via an input argument. I have no doubt these problems
are due to my limited knowledge of advanced Tex/Latex macro
programming. Any help with this would be appreciated. My objective is
to typeset data tables which are in plot format rather than TeX
format. Possible advanced options would be to only print selected
columns and possibly provide the column labels in the data file and have
them typeset in mathmode, or formatting of numerical data. Any
input/help or simplifications would be appreciated.
\begin{filecontents}{doterrorbar.dat}
1.00E+001 2.00E+001 3.00E+001 4.00E+001
2.00E+001 3.00E+001 4.00E+001 5.00E+001
3.00E+001 4.00E+001 5.00E+001 6.00E+001
4.00E+001 5.00E+001 6.00E+001 7.00E+001
\end{filecontents}
\documentclass[]{article}
\usepackage{pst-all}
\usepackage{pstricks-add}
\usepackage{ifthen}
\makeatletter
\def\colform{|c|c|c|c|} %This should be constructed via a loop and
\@datawidth
%\def\colform{|}
\newcounter{loopcount}
\newcounter{rowcount}
\def\PrintCoordinates#1#2{%
\hline
\def\@datawidth{#2}
\setcounter{loopcount}{0}
\setcounter{rowcount}{0}
\expandafter\PrintCoordinates at i#1
}
\def\PrintCoordinates at i#1{\PrintCoordinates at ii#1}
\def\PrintCoordinates at ii D #1 {%
\stepcounter{loopcount}%
#1
%\ifthenelse{\value{rowcount}<1}{\xdef\colform{\ignorespaces\colform c|}}{}
\@ifnextchar D{%
\ifthenelse{\value{loopcount}=4}{% the value 4 should be \@datawidth
\\ \hline
\setcounter{loopcount}{0}
\stepcounter{rowcount}}{&}
\PrintCoordinates at ii}{%
\\ \hline
}
}
\makeatother
\begin{document}
\pagestyle{empty}
\pagenumbering{arabic}
\readdata{\dataA}{data/doterrorbar.dat}
\begin{tabular}[t]{\colform}
\hline
$X$ & $Y$ & $\Delta X$ & $\Delta Y$ \\
\PrintCoordinates{\dataA}{4}
\end{tabular}
\end{document}
More information about the PSTricks
mailing list