7

I am trying to do the following:

  1. read a csv (or other similar format) external file with numerical and string data into an object;

  2. reference/get an specific value from such object to use into an specific cell of a table or in a figure.

That means, I do not want to convert a csv file or such into a table. I do not want to use packages to build a table.

So, for instance, suppose that I have the following code to generate a very simple table:

\documentclass[]{article}

\begin{document}

\begin{table}[]
    \centering
    \caption{My example}
    \begin{tabular}{lllll}
        1  & 2  & 3  & 4  & 5 \\
        6  & 7  & 8  & xyz  & 9 \\
        10 & 11 & 12 & 13 & 14
    \end{tabular}
\end{table}

\end{document}

Where it is written "xyz", I want to actually write a command that references/gets the value of a specific row/column of a csv or similar file. Is there a way to accomplish such a thing?

0

1 Answer 1

0

The readarray package may be of use in this endeavor.

\begin{filecontents*}{myfile.csv}
Name, Age, Profession
Mike Smith, 33, engineer
Sally Doe, 27, hairdresser
Jane Harding, 57, mathematician
\end{filecontents*}

\documentclass[]{article}
\usepackage{readarray}
\readarraysepchar{,}
\begin{document}
\readdef{myfile.csv}\mydata
\readarray*\mydata\myarray[-,\ncols]
\begin{table}[]
    \centering
    \caption{My example}
    \begin{tabular}{lllll}
        1  & 2  & 3  & 4  & 5 \\
        6  & 7  & 8  & ``\myarray[3,3]''  & 9 \\
        10 & 11 & 12 & 13 & 14
    \end{tabular}
\end{table}
The array \textbackslash myarray has \myarrayROWS{} rows,
\myarrayCOLS{} columns, for a total of \myarrayCELLS{} cells.
The first column of row four contains ``\myarray[4,1]''.
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .