4

I am running WinEdt 9.0, MikTex 2.9 on windows 7 pro.

I am constructing a standard format PDF report and must follow that format (ie the table is in a particular format with colors and fonts etc etc). To be clear, the table layout is complex and predefined. All I have to do is add the data points.

The format requires large tables to be populated with float data points which are held in a CSV file on my PC.. There seems to be a number of ways of doing this but i am not sure which is the simplest. Ideally I would like to be able to "index into" myFile.txt eg x= load(myFile.txt), val1 = x(3,17); etc

How do I assign values from "myFile.txt" to my variables val1, val2, val3, val4?

my MWE is below. thank you!

            \documentclass{article}
            \usepackage[T1]{fontenc}
            \usepackage{caption}
            \usepackage{float}
            \usepackage{xspace}
            \usepackage{verbatim}
        \usepackage{array}
        \usepackage{multirow}
        \usepackage{hhline}
        \usepackage{ifthen}
        %http://www.tug.org/texmf-dist/doc/latex/pgfplots/pgfplotstable.pdf

        \newread\file
        \openin\file=A:/myReports/latestResults/myFile.txt
        \loop\unless\ifeof\file
            \read\file to\fileline % Reads a line of the file into \fileline
            % Do something with \fileline
        \repeat
        \closein\file

        \begin{tabular}{|c|c|c|}
          \hline
          t1 & t2 & t3 \\
          y1 & val1 & val4 \\
          y2 & val2 & val3 \\
          \hline
        \end{tabular}
        \end{document}

closed as unclear what you're asking by Symbol 1, Stefan Pinnow, Mico, user31729, egreg Apr 1 '17 at 9:15

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • For further reference: LaTeX Community – Johannes_B Sep 24 '14 at 12:14
  • Why is this tagged pgfplotstable if you don't load pgfplotstable? – darthbith Sep 24 '14 at 12:15
  • Can you include some data rows from your CSV file to play with? @darthbith It's probably the question how to do in pgfplotstable. – percusse Sep 24 '14 at 12:31
  • You could use pgfplotstable both to read in the data and to parse it (see \pgfplotstablegetelem). Since your tabular uses data from one row of your csv to fill more than one row of the tabular, \pgfplotstabltypeset will not be a good idea. – John Kormylo Sep 24 '14 at 16:24
0

An easy option is using knitr:

mwe

\documentclass[twocolumn]{article}
\usepackage{booktabs}
\parskip1em\parindent0pt
\begin{document}
The CSV file: 
<<echo=F,comment=NA>>=
Val <- read.csv("values.csv",header=T)
val <- Val$Values ## just to simplify the \Sexpr 
Val
@
The \LaTeX\ table:\par
\begin{tabular}{ccc}\toprule
t1 & t2 & t3 \\\midrule
y1 & \Sexpr{val[1]} & \Sexpr{val[4]} \\
y2 & \Sexpr{val[2]} & \Sexpr{val[3]} \\
\bottomrule
\end{tabular}
\end{document}            

Not the answer you're looking for? Browse other questions tagged or ask your own question.