# The index of head row doesn't begin with 1

This seems a very simple question, but I cannot find an answer.

I have a very simple CSV file and I want to make a LaTeX table from it.

tiny.csv

-1, 1, -1, 1
2, 4, 6, 8
3, 9, 27, 81

LaTeX file

\documentclass{standalone}
\usepackage{pgfplotstable}

\begin{document}

\pgfplotstabletypeset[col sep=comma]{tiny.csv}

\end{document}

Then I have a table as follows:

0  1   2   3       <- head row
−1  1  −1   1
2  4   6   8
3  9  27  81

I wish the numbers in the head row to begin with 0, not 1. And I don't want to change the file tiny.csv as it will be used by other scripts for experiment. How can I change the head row to '1 2 3 4' from '0 1 2 3'?

-

You can alter the internal PGFPlotstable macro that assigns the numeric column names. Here's a way that introduces a new key first numeric column name=<number> that allows to specify the starting number of the automatic column names. By default it's set to 0 so the normal behaviour isn't changed. If you set first numeric column name=1, the numbering will start with 1:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplotstable}

\makeatletter
\pgfplotstableset{first numeric column name/.initial=0}
\newcounter{numeric@colname}
\pgfutil@loop
\edef\pgfplotstable@loc@TMPb{\thenumeric@colname}%
\expandafter\pgfplotslistpushbackglobal\pgfplotstable@loc@TMPb\to\pgfplotstable@colnames@glob
\pgfutil@repeat
}
\makeatother

\begin{document}

\pgfplotstabletypeset[col sep=comma, first numeric column name=1]{
-1, 1, -1, 1
2, 4, 6, 8
3, 9, 27, 81
}

\end{document}
-
No wonder I couldn't find that:-) – David Carlisle Mar 19 '13 at 9:27
Isn't adding just 1 to the @cell content more practical with every head row? – percusse Mar 19 '13 at 11:56
@percusse: Depends on what you want to do. That approach wouldn't change the actual column name, so you couldn't refer to the columns using the same numbers. Feel free to add an answer, though. – Jake Mar 19 '13 at 12:10

One option would be to use column name inside the columns style:

\documentclass{standalone}
\usepackage{pgfplotstable}

\begin{document}

\pgfplotstabletypeset[col sep=comma,
columns/0/.style={column name=$1$},
columns/1/.style={column name=$2$},
columns/2/.style={column name=$3$},
columns/3/.style={column name=$4$},
]{tiny.cvs}

\end{document}

-
Hmm. OK, I can live with this option. Then, I want to generalize this approach so that I can use a for loop. (maybe \foreach?) Is that possible? – Federico Magallanez Mar 19 '13 at 6:19
@FedericoMagallanez see Jake's answer. – Gonzalo Medina Mar 19 '13 at 12:19