6

I have some x y data that I wish to typeset using pgfplotstable, rather than having say 9 rows of 2 columns, I would like to have 3 rows, with 3 sets of xy pairs.

Consider the following:

\documentclass{article}
\usepackage{pgfplotstable,filecontents}

\begin{filecontents}{mydata.dat}
    x y x y x y
    0 0 3 3 6 6
    1 1 4 4 7 7
    2 2 5 5 8 8
\end{filecontents}

\begin{document}
    \pgfplotstableset{
        columns/x/.style={
             column name={$X$},
        },
        columns/y/.style={
              column name={$Y$},
              column type/.add={}{|}
        },
    }
    \pgfplotstableread{mydata.dat}\loadedtable
    \pgfplotstabletypeset{\loadedtable}
\end{document}

Which produces the following output:

Output

Clearly columns 2 to 6, in this MWE are not being typeset as desired. I am aware that this can be resolved by declaring unique column style for each column as follows:

\pgfplotstableset{
  columns/A/.style={
    column name={$X$},
  },
  columns/B/.style={
    column name={$Y$},
    column type/.add={}{|}
  },
  columns/C/.style={
   column name={$X$},
  },
  columns/D/.style={
    column name={$Y$},
    column type/.add={}{|}
  },
  columns/E/.style={
    column name={$X$},
  },
  columns/F/.style={
    column name={$Y$},
    column type/.add={}{|}
  },
}

Also slightly modifying the input data structure:

\begin{filecontents}{mydata.dat}
    A B C D E F
    0 0 3 3 6 6
    1 1 4 4 7 7
    2 2 5 5 8 8
\end{filecontents}

Producing the desired format, with column names [X Y X Y X Y]:

Desired

But I am trying to avoid having to effectively re-type the same code over and over. How can I use the same pgfplotstableset column style, for multiple columns in the same table.

  • So you want the title row to read X Y X Y X Y, correct? – Jake Oct 24 '13 at 19:39
  • Yes. Exactly... – Nicholas Hamilton Oct 24 '13 at 19:39
  • @Jake, I have updated the question to reflect this. – Nicholas Hamilton Oct 24 '13 at 19:42
6

You can use the every odd column and every even column styles for this (noting that the column numbering starts at zero):

\documentclass{article}
\usepackage{pgfplotstable,filecontents}

\begin{filecontents}{mydata.dat}
    x y x y x y
    0 0 3 3 6 6
    1 1 4 4 7 7
    2 2 5 5 8 8
\end{filecontents}

\begin{document}
    \pgfplotstableset{
        every even column/.style={
            column name={$X$}
        },
        every odd column/.style={
            column name={$Y$},
            column type/.add={}{|}
        }
    }
    \pgfplotstableread{mydata.dat}\loadedtable
    \pgfplotstabletypeset{\loadedtable}
\end{document}
  • so what if there another number, say 4 or 5? unique columns, that repeat? This only works if there is 2. – Nicholas Hamilton Oct 24 '13 at 19:44
  • @ADP: Good point. For rows, there's the every nth row style, but for columns, that's not implemented yet. Might be worth opening a feature request for that. – Jake Oct 25 '13 at 7:14

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.