# pgfplotstable not displaying column names

I'm trying to make a multi-page table from a txt file by using longtable and pgfplotstable. For some reason, whenever I use

"display columns/0/.style={column name={Col0}}"


for example, the column name doesn't print. I am a beginner so I'm just a bit confused.

I've been through the documentation for pgfplotstable and been trying to debug for hours, but I can't figure it out.

My MWE:

\documentclass{article}
\usepackage{booktabs} % For \toprule, \midrule and \bottomrule
\usepackage{siunitx} % Formats the units and values
\usepackage{pgfplotstable} % Generates table from .csv
\usepackage{longtable} % To display tables on several pages
\usepackage{array}
\usepackage{bm}
\usepackage{hyperref}

\pgfplotsset{compat=1.14} %I was getting backwards compatibility errors

\begin{document}

%%% Code from Dr. Christian for not using headers
\pgfkeysifdefined{/pgfplots/table/output empty row/.@cmd}{
\pgfplotstableset{
}
}
}

\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}

\pgfplotstabletypeset[
col sep=space,
before row={%
\caption{The caption}
\label{tab:DataTable}
\\ \toprule
\\ \midrule
%
\multicolumn{3}{c}{{\bfseries \tablename\ \thetable{} -- continued from previous page}}
\\ \toprule
\\ \midrule
%
\midrule
\multicolumn{3}{r}
{{Continued on next page}}
\\ \bottomrule
\endfoot
%
\midrule
\multicolumn{3}{r}{}
\\ \bottomrule
\endlastfoot
}
},
display columns/0/.style={
dec sep align,
sci, sci zerofill,
column name={RA}
},
display columns/1/.style={
dec sep align,
sci, sci zerofill,
column name={Dec}
},
display columns/2/.style={
dec sep align,
sci, sci zerofill,
column name={S}
}
]{ra_dec_aveflux_Jy.txt}

\end{document}


UPDATE: Here is a sample of my txt file:

1e+01 2e+01 3e+01
4e+01 5e+01 6e+01
7e+01 8e+01 9e+01


I think perhaps you need to specify the header in the every head row style, instead of adding column name. That is, in the header instructions for longtable, add a row with RA, Dec and S.

There is one thing to note though: The dec sep align option you use for the three columns actually creates two columns in the generated tabular. Hence, you need to use e.g. \multicolumn{2}{c}{RA}.

Another thing to note is that the "continued from last page"-header you defined is wider than the table would be if it just contained numbers. (At least with the values you showed.) This in turn messes up the horizontal alignment of the last column, which I don't know how to fix. The workaround presented below is to split that text across two rows, making it narrow enough.

\documentclass{article}
\usepackage{booktabs} % For \toprule, \midrule and \bottomrule
\usepackage{siunitx} % Formats the units and values
\usepackage{pgfplotstable} % Generates table from .csv
\usepackage{longtable} % To display tables on several pages
\usepackage{array}
\usepackage{bm}
\usepackage{hyperref}

\pgfplotsset{compat=1.14} %I was getting backwards compatibility errors

\begin{document}

%%% Code from Dr. Christian for not using headers
\pgfkeysifdefined{/pgfplots/table/output empty row/.@cmd}{
\pgfplotstableset{
}
}
}

\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}

\pgfplotstabletypeset[
col sep=space,
%    column type/.add={|}{}, % don't use vertical rules along with booktabs rules
before row={%
\caption{The caption}
\label{tab:DataTable}
\\ \toprule
% the dec sep align options makes two tabular columns, so we need multicolumn for the header
\multicolumn{2}{c}{RA} & \multicolumn{2}{c}{Dec} & \multicolumn{2}{c}{S}
\\ \midrule
%
% split this over two lines, so that it doesn't make the table too wide
\multicolumn{6}{l}{{\bfseries \tablename\ \thetable{} -- continued from}} \\
\multicolumn{6}{l}{{\bfseries previous page}}
\\ \toprule
\multicolumn{2}{c}{RA} & \multicolumn{2}{c}{Dec} & \multicolumn{2}{c}{S}
\\ \midrule
%
\midrule
\multicolumn{6}{c}
{{Continued on next page}}
\\ \bottomrule
\endfoot
%
%            \midrule
%            \multicolumn{6}{r}{}
\\ \bottomrule
\endlastfoot
}
},
display columns/0/.style={
dec sep align,
sci, sci zerofill,
%        column name={RA}
},
display columns/1/.style={
dec sep align,
sci, sci zerofill,
%        column name={Dec}
},
display columns/2/.style={
dec sep align,
sci, sci zerofill,
column type/.add={}{}, % removed the |
%        column name={S}
}
]{data.dat}

\end{document}

• Thanks! That got the column names to show up, but they don't seem to be in the header and they don't repeat on each page. Is there a way to get the names as given in the "display columns" command to show up in the header on each page? Jun 28 '18 at 21:22
• @OrielFarajun Right, sorry. Specify them in the every head row style. I'll update in a bit, though there is one thing I don't know how to fix. I'll ping when I've updated, and you'll see. Jun 28 '18 at 21:28
• @OrielFarajun See updated answer. Jun 28 '18 at 21:38