3

Consider the rows in table testdataExisting.dat:

  • If type=0, vala must be put in a row. valb should not be displayed.
  • If type=1, vala must be put in a row and valb must be put in the subsequent row with the same id, possibly via using multirow.

My MWE:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{pgfplotstable}
\pgfplotsset{width=10cm,compat=1.6}
\usepackage{filecontents}


\begin{filecontents}{testdataExisting.dat}
id vala valb type
1  24   75   0
2  56   87   1
3  11   46   0
\end{filecontents}

\begin{filecontents}{testdataGenerated.dat}
id val  type
1  24   0
2  56   1
2  87   1
3  11   0
\end{filecontents}
 \begin{document}
Table 1

 \pgfplotstabletypeset[col sep=space,columns={id,vala,valb,type},]{testdataExisting.dat}

Table 2

 \pgfplotstabletypeset[col sep=space,columns={id,val,type},
    columns/type/.style={string type,column type=r},
 ]{testdataGenerated.dat}
 \end{document}

Output:

Here is a solution of another problem that is similar to this problem. I could not adapt that solution for this problem. I was not able to handle addition of a new row which is triggered depending on the values. I need a solution using PgfplotsTable.

1
\documentclass{article}
\usepackage{readarray}
\begin{document}
\readdef{testdataExisting.dat}{\data}
\readArrayij{\data}{raw}{\ncols}

\begin{tabbing}
\= \Arrayij{raw}{1}{1} ~~~~~~\= val  ~~~~~\= \Arrayij{raw}{1}{\ncols}\\
\newcounter{index}\setcounter{index}{1}%
\whiledo{\value{index} < \nrows}{
  \addtocounter{index}{1}%
  \>\Arrayij{raw}{\value{index}}{1} \> \Arrayij{raw}{\value{index}}{2}%
                                   \> \Arrayij{raw}{\value{index}}{\ncols}\\
  \if 1\csname rawX\roman{index}Xiv\endcsname%
    \>\Arrayij{raw}{\value{index}}{1} \> \Arrayij{raw}{\value{index}}{3}%
                                   \> \Arrayij{raw}{\value{index}}{\ncols}\\
  \fi%
}
\end{tabbing}

\end{document}

where the file testdataExisting is

id vala valb type
1  24   75   0
2  56   87   1
3  11   46   0

The output is:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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